java 存根,Java方法存根

This is what I have to do:

Define stubs for the methods called by the below main(). Each stub should print "FIXME: Finish methodName()" followed by a newline, and should return -1.

Example output:

FIXME: Finish getUserNum()

FIXME: Finish getUserNum()

FIXME: Finish computeAvg()

Avg: -1

This is the code that I have:

import java.util.Scanner;

public class MthdStubsStatistics {

public static int methodName (int userNum1, int userNum2, int computerAvg) {

System.out.println("FIXME: Finish getUserNum()");

System.out.println("FIXME: Finish getUserNum()");

System.out.println("FIXME: Finish computerAvg()");

System.out.println("Avg: -1");

return 0;

}

public static void main() {

int userNum1 = 0;

int userNum2 = 0;

int avgResult = 0;

userNum1 = getUserNum();

userNum2 = getUserNum();

avgResult = computeAvg(userNum1, userNum2);

System.out.println("Avg: " + avgResult);

return;

}

}

I thought I understood method stubs, but I feel like I am making a very stupid and simple mistake? I can only edit the public static int methodName section of the code.

解决方案

A method stub in this sense is a method with no real substance, i.e. it's not doing what it is intended to do. Your getUserNum() method should return a user's unique ID, but instead you're defining a stub that simply returns -1 on every invocation.

You can tell from your main() method, you're supposed to be defining these two methods:

userNum1 = getUserNum();

avgResult = computeAvg(userNum1, userNum2);

So, define them. Here's what the getUserNum() stub would look like.

public static int getUserNum() {

System.out.println("FIXME: Finish getUserNum()");

return -1;

}

I'll leave computeAvg() up to the OP.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值