// ITI 1120 // Name: Diana Inkpen, Student# 123456 //import java.io.*; /** * This program computes the average of three costs (for three books). */ class Average3 { public static void main (String[] args) { // DECLARE VARIABLES/DATA DICTIONARY double cost1; // GIVEN three costs double cost2; // GIVEN double cost3; // GIVEN double avgCost; // RESULT: average cost // READ IN GIVENS System.out.println( "Enter the first number:" ); cost1 = ITI1120.readDouble( ); System.out.println( "Enter the second number:" ); cost2 = ITI1120.readDouble( ); System.out.println( "Enter the third number:" ); cost3 = ITI1120.readDouble( ); // CALLS THE ALGORITHM avgCost = average(cost1, cost2, cost3); // PRINT OUT RESULTS AND MODIFIEDS System.out.println( "The average cost is " + avgCost); //could call the algorithm again if needed avgCost = average(68.5, 70, 35.6); System.out.println( "The average cost for the second call of the method is " + avgCost); } /** * This method computes the average of three numbers. */ public static double average ( double num1, double num2, double num3) { // VARABLE DECLARATIONS double avg; // RESULT: average of num1, num2, num3 //BODY OF THE ALGORITHM avg = (num1 + num2 + num3) / 3; // RETURN RESULTS return avg; } }