这就是我要做的事情:
为以下main()调用的方法定义存根。每个存根应打印" FIXME:完成methodName()"后面跟一个换行符,应该返回-1。
示例输出:
FIXME: Finish getUserNum()
FIXME: Finish getUserNum()
FIXME: Finish computeAvg()
Avg: -1
这是我的代码:
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;
}
}
我以为我理解了方法存根,但我觉得我犯了一个非常愚蠢和简单的错误?我只能编辑代码的public static int methodName部分。
答案 0 :(得分:1)
这种意义上的方法存根是一种没有实质内容的方法,即它没有按照预期的方式进行。您的if let urlString = NSBundle.mainBundle().pathForResource("MyFramework", ofType: "framework", inDirectory: "Frameworks") {
let bundle = (NSBundle(URL: NSURL(fileURLWithPath: urlString)))
let sb = UIStoryboard(name: "Main", bundle: bundle)
let vc = sb.instantiateViewControllerWithIdentifier("vc")
self.showViewController(vc, sender: nil)
}
方法应返回用户的唯一ID,而是定义一个只在每次调用时返回getUserNum()
的存根。
您可以通过-1
方法判断,您应该定义这两种方法:
main()
所以,定义它们。这是userNum1 = getUserNum();
avgResult = computeAvg(userNum1, userNum2);
存根的样子。
getUserNum()
我会将public static int getUserNum() {
System.out.println("FIXME: Finish getUserNum()");
return -1;
}
留给OP。
答案 1 :(得分:0)
import java.util.Scanner;
公共类MthdStubsStatistics {/ *你的解决方案就在这里* /
public static int getUserNum(){ System.out.println(“FIXME:完成getUserNum()”);
返回-1;
}
public static int computeAvg(int userNum1,int userNum2){ int avgResult =(userNum1 + userNum2)/ 2; System.out.println(“FIXME:Finish computeAvg()”); 返回-1;
} 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);
返回;
} }
答案 2 :(得分:0)
import java.util.Scanner;
public class MthdStubsStatistics {
public static int getUserNum() {
System.out.println("FIXME: Finish getUserNum()");
return -1;
}
public static int computeAvg(int userNum1, int userNum2) {
System.out.println("FIXME: Finish computeAvg()");
return -1;
}
public static void main(String [] args) {
int userNum1;
int userNum2;
int avgResult;
userNum1 = getUserNum();
userNum2 = getUserNum();
avgResult = computeAvg(userNum1, userNum2);
System.out.println("Avg: " + avgResult);
}
}
答案 3 :(得分:0)
import java.util.Scanner;
public class MthdStubsStatistics {
public static int getUserNum() {
System.out.println("FIXME: Finish getUserNum()");
return -1;
}
public static int computeAvg(int a, int b) {
System.out.println("FIXME: Finish computeAvg()");
return -1;
}
public static void main(String [] args) {
int userNum1;
int userNum2;
int avgResult;
userNum1 = getUserNum();
userNum2 = getUserNum();
avgResult = computeAvg(userNum1, userNum2);
System.out.println("Avg: " + avgResult);
}
}
答案 4 :(得分:0)
export default const workspace = new class Workspace {
// ...constructor (if desired), properties, and methods...
}();