Define stubs for the methods called by the below main(). Each stub should print “FIXME: Finish…
The following solution is suggested to handle the subject “Define stubs for the methods called by the below main(). Each stub should print “FIXME: Finish…“. Let’s keep an eye on the content below!
Question “Define stubs for the methods called by the below main(). Each stub should print “FIXME: Finish…”
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 computeAverage() Avg: -1
import java.util.Scanner;
public class MethodStubs{
/* Your solution goes here */
public static void main(String [] args) {
int userNum1;
int userNum2;
int avgResult;
MethodStubs stubTester = new MethodStubs();
userNum1 = stubTester.getUserNum();
userNum2 = stubTester.getUserNum();
avgResult = stubTester.computeAverage(userNum1, userNum2);
System.out.println(“Avg: ” + avgResult);
}
}
Answer
public class MethodStubs {
public int getUserNum() {
System.out.println(“FIXME: Finish getUserNum()”);
return –1;
}
public int computeAverage(int n1, int n2) {
System.out.println(“FIXME: Finish computeAverage()”);
return –1;
}
public static void main(String[] args) {
int userNum1;
int userNum2;
int avgResult;
MethodStubs stubTester = new MethodStubs();
userNum1 = stubTester.getUserNum();
userNum2 = stubTester.getUserNum();
avgResult = stubTester.computeAverage(userNum1, userNum2);
System.out.println(“Avg: “ + avgResult);
}
}
Conclusion
Above is the solution for “Define stubs for the methods called by the below main(). Each stub should print “FIXME: Finish…“. We hope that you find a good answer and gain the knowledge about this topic of engineering.