Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java Define stubs for the methods called by the below main(). Each stub shoul

ID: 3593212 • Letter: I

Question

In Java 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

import java.util.Scanner;

public class MthdStubsStatistics {

   /* Your solution goes here */

   public static void main(String [] args) {
      int userNum1 = 0;
      int userNum2 = 0;
      int avgResult = 0;

      userNum1 = getUserNum();
      userNum2 = getUserNum();

      avgResult = computeAvg(userNum1, userNum2);

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

      return;
   }
}

Explanation / Answer

import java.util.Scanner;

public class MthdStubsStatistics {

/* Your solution goes here */

public static void main(String[] args) {

int userNum1 = 0;

int userNum2 = 0;

int avgResult = 0;

userNum1 = getUserNum();

userNum2 = getUserNum();

avgResult = computeAvg(userNum1, userNum2);

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

return;

}

private static int computeAvg(int userNum1, int userNum2) {

// TODO Auto-generated method stub

return (userNum1 + userNum2) / 2;

}

private static int getUserNum() {

// TODO Auto-generated method stub

Scanner scanner = null;

int num = 0;

try {

scanner = new Scanner(System.in);

System.out.print("Enter the Number: ");

num = scanner.nextInt();

} catch (Exception e) {

// TODO: handle exception

}

return num;

}

}

OUTPUT:

Enter the Number: 4
Enter the Number: 6
Avg: 5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote