/** 10/29/2018 * Problem: Read in a set of grades * 1. calculate average * 2. Find max * 3. Find min * 4. Count number of grades greater than the average. * This version is Solution 1. We use a single variable to keep * reading in the next value. This is easily done in a LOOP. * Advantage: programming scales up and is easier * Disadvantage: data is not here to solve part 4 of the problem. */ import java.io.*; import java.util.Scanner; public class Grades { public static void main(String[] args) throws IOException { Scanner infile = new Scanner(new File("grades.txt")); // Read in data (which is a header value followed by #s) int num = infile.nextInt(); double grade, sum=0.0; // initialize max to first data element double max = infile.nextDouble(); double min = max; // initialize max and min to first value int higherAvg=0; // Keep a running sum to calculate the average for (int i=0; i max) max = grade; System.out.println("i=" + i + " running max is: " + max); if (grade < min) min = grade; // how many grades are higher than average // if (grade > average) // higherAvg++; } double average = sum/num; System.out.println("\naverage: " + average + " max: " + max + " min: " + min); } }