I wrote below code to satisfy program requirement as follows:
Average of Three Write a program that reads three whole numbers and displays the average of the three numbers.
Input Notes: Three whole numbers (non-negative integers) are entered at the console.
Output Notes (Prompts and Labels): The program prompts for the three integers with these strings: "Enter the first integer.", "Enter the second integer.", "Enter the third integer.". The program then prints The average of NUMBER1, NUMBER2, and NUMBER3 = AVG where NUMBER1 is the first integer value entered and NUMBER2 and NUMBER3 the subsequent integers, and AVG is the computed average value.
SPECIFICATION OF NAMES: Your application class should be called Average3:
My source code:
import java.util.Scanner;
public class Average3 {
/**
* @param args
*/
public static void main(String[] args) {
int AVG, NUMBER1, NUMBER2, NUMBER3;
System.out.println("Enter the first integer.");
Scanner keyboard = new Scanner(System.in);
NUMBER1 = keyboard.nextInt();
System.out.println("Enter the second integer.");
NUMBER2 = keyboard.nextInt();
System.out.println("Enter the third integer.");
NUMBER3 = keyboard.nextInt();
AVG = (NUMBER1 + NUMBER2 + NUMBER3) / 3;
System.out.println("The average of NUMBER1, NUMBER2, and NUMBER3 = " + AVG);
}
}
My program compiles fine but I know I could have implemented and invoked an object with an associated method but am struggling where to start I understand the methods and objects conceptually but not as far as writing code. Anyone have any suggestions?