/* this is a variation of program 7.1 on page 276. Here, we input a number of test scores from the user ending with a -1 (or any negative number), find the highest grade, * and determine the letter grade cutoffs as max-10 for the cutoff for an A, max-20 for B, etc, and then look at all the scores to count the number of As, Bs, etc. */ import java.util.Scanner; public class Prog7_1 { public static void main(String[] args) { int[] scores = new int[100]; // assume no more than 100 scores int temp; // the next input score int number = 0; // the number of scores so far input, used to control our for loops Scanner in = new Scanner(System.in); System.out.print("Enter the first test score, enter -1 to exit "); // get the first score temp = in.nextInt(); while(temp>=0&&number<100) // iterate while the scores are legal (>= 0) and we haven't filled the array yet { scores[number]=temp; // place the latest input into the array number++; // and now that the array has 1 more element, increment number System.out.print("Enter the next test score, enter -1 to exit "); temp = in.nextInt(); } int max = scores[0]; // now locate the largest value, we start assuming its the first value for(int i=1;imax) max=scores[i]; int aScore = max-10; // compute the grade breakdown int bScore = max-20; int cScore = max-30; int dScore = max-40; int numA = 0, numB = 0, numC = 0, numD = 0, numF = 0; // counters for the number of A scores, B scores, etc for(int i=0;i=aScore) numA++; else if(scores[i]>=bScore) numB++; else if(scores[i]>=cScore) numC++; else if(scores[i]>=dScore) numD++; else numF++; // if not in any of the above ranges, it must be an F // output the results System.out.println("Of " + number + " scores entered, " + numA + " were As, " + numB + " were Bs, " + numC + " were Cs, " + numD + " were Ds and " + numF + " were Fs"); } }