/* filename: Average.java description: My first java program: collects numbers then adds and averages them author: Kalin Ringkvist, k.rainquist@comcast.net version: 1.00 200-01-10 */ //import the io package so we can use the BufferedReader class import java.io.*; public class Average { //instantiate the BufferedReader class and assign to the reference keyboard static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { //declare all 12 variables double num1, num2, num3, num4, num5, avg; int int1, int2, int3, int4, int5, total; //ask for each decimal number in sequence and place in "num" variables as doubles System.out.println("Enter the first decimal number:"); num1 = Double.parseDouble(keyboard.readLine()); System.out.println("Enter the second decimal number:"); num2 = Double.parseDouble(keyboard.readLine()); System.out.println("Enter the third decimal number:"); num3 = Double.parseDouble(keyboard.readLine()); System.out.println("Enter the fourth decimal number:"); num4 = Double.parseDouble(keyboard.readLine()); System.out.println("Enter the fifth decimal number:"); num5 = Double.parseDouble(keyboard.readLine()); //Print out the same numbers entered System.out.println("Your numbers are " + num1 + ", " + num2 + ", " + num3 + ", " + num4 + ", and " + num5 + " These had better be correct!" ); //convert each number to its nearest integer int1 = (int)(num1 + 0.5); int2 = (int)(num2 + 0.5); int3 = (int)(num3 + 0.5); int4 = (int)(num4 + 0.5); int5 = (int)(num5 + 0.5); //add up all the resulting integers total = int1 + int2 + int3 + int4 + int5; //take the total and average it avg = ((double)(total)) / 5; //Print all the results in two sets to avoid broken lines System.out.println("Your new rounded integers are " + int1 + ", " + int2 + ", " + int3 + ", " + int4 + ", and " + int5 + "."); System.out.println("Your total is " + total + ", and your average is " + avg + ". Lucky numbers!"); } }