Answer to Question #238366 in Java | JSP | JSF for java

Question #238366

Write a program called GradeBookMethod.java. This program should do the following:

1. Prompt the user to enter 3 grades (assume the grades are integer numbers)

2. Compute the average of the 3 grades by calling a method, which you write, named: average( )

3. Print the resulting average (do not worry about rounding the result, just print the value with all of the decimal places)

The average( ) method will:

1.  Take 3 integer values as the input parameters

2.  Calculate the average of the three integers (what data type should the average be?)

3.  Return the average.

Here is an example of what the program output will look like (bold-italics indicate user input):

Enter grade 1: 89

Enter grade 2: 93

Enter grade 3: 72

84.666666667 



1
Expert's answer
2021-09-17T02:04:34-0400


import java.util.Scanner;


public class GradeBookMethod {


	public static void main(String[] args) {
		Scanner keyboard = new Scanner(System.in);
		int grade1, grade2, grade3;
		// 1. Prompt the user to enter 3 grades (assume the grades are integer numbers)
		System.out.print("Enter grade 1: ");
		grade1 = keyboard.nextInt();
		System.out.print("Enter grade 2: ");
		grade2 = keyboard.nextInt();
		System.out.print("Enter grade 3: ");
		grade3 = keyboard.nextInt();
		// 2. Compute the average of the 3 grades by calling a method, which you write,
		// named: average( )
		double average = average(grade1, grade2, grade3);
		// 3. Print the resulting average (do not worry about rounding the result, just
		// print the value with all of the decimal places)
		System.out.println(average);
		keyboard.close();
	}


	/**
	 * The average( ) method will:
	 * 
	 * 1. Take 3 integer values as the input parameters
	 * 
	 * 2. Calculate the average of the three integers (what data type should the
	 * average be?) Answer: double type
	 * 
	 * 3. Return the average.
	 * 
	 * @param grade1
	 * @param grade2
	 * @param grade3
	 * @return
	 */
	private static double average(int grade1, int grade2, int grade3) {
		return (double) ((grade1 + grade2 + grade3) / 3.0);
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS