//CS5-HMC-Sp,00-HW10-5 //A. Khakpour, Apr., 00 import java.io.*; import java.text.*; class ExamGrades1 { //----------------------------------------------------------------- // Computes the average, minimum, and maximum of a set of exam // scores entered by the user. //----------------------------------------------------------------- public static void main (String[] args) throws IOException { InputStreamReader a = new InputStreamReader(System.in); BufferedReader b = new BufferedReader(a); String c; int grade, count = 0, sum = 0, max, min; double average; // Get the first grade and give min and max that initial value System.out.print ("Enter the first grade (-1 to quit): "); c = b.readLine(); grade = Integer.parseInt(c); max = min = grade; // Read and process the rest of the grades while (grade >= 0) { count++; sum += grade; if (grade > max) max = grade; else if (grade < min) min = grade; System.out.print ("Enter the next grade (-1 to quit): "); c = b.readLine(); grade = Integer.parseInt(c); } // Produce the final results if (count == 0) System.out.println ("No valid grades were entered."); else { DecimalFormat fmt = new DecimalFormat ("0.##"); average = (double)sum / count; System.out.println(); System.out.println ("Total number of students: " + count); System.out.println ("Average grade: " + fmt.format(average)); System.out.println ("Highest grade: " + max); System.out.println ("Lowest grade: " + min); } } }