View Question
 ```Extend the program below to compute the average score for the whole class. You will add the appropriate code so that the program will: Ask the user to enter the total number of students in the class Ask the user to enter the scores (assignment and project) for each student. Print out the numeric score and the letter grade for each student Compute the average grade of the class Procedure Modify the program using a "for" loop. Extend the program for multiple students using a "while" loop. Although you could use either kind of loop. // Program to manage the grades of students in a course. public class ExamsApp { public static void main(String[] args) { Exams ex = new Exams(); Ex.findSumAndCount(); System.out.println(“Average score is “ + ex.findAve()); } } // Program to manage the grades of students in a course. import javax.swing.JOptionPane; public class Exams { // Data fields { private int sum; //sum of scores private int count; // count of scores // methods public static int readInt(String prompt) { String numStr = JOptionPane.showInputDialog(prompt); return Integer.parseInt(numStr); } // preconditions: count and sum are zero // postconditions: data field sum stores the sum of scores // data field count stores the count of scores public void findSumAndCount() { int score; int SENTINEL = -1; //sentinel value score = readInt(“Enter student’s first grade or “ + SENTINEL + “ to stop”); while (score != SENTINEL) { sum += score; // add current score to sum count++; // increase count by 1 System.out.println(“score: “ + score); score = readInt(“Enter next grade or “ + SENTINEL + “ to stop”); } } // precondition: sum and count are defined // postcondition: Returns the average score public double findAve() { double average; // average score if (count > 0) average = (double) sum / (double) count; else average = 0; return average; } }``` Request for Question Clarification by mathtalk-ga on 09 Jan 2003 14:23 PST ```OFF TOPIC - sort of... Hi, math01-ga: I'd answered a few questions for you in the past, but never got a rating. No big deal, it's certainly your option - but I kind of got the impression that my approach to answering just wasn't your cup of tea, or something. So I've stood back and let others be of assistance. However today I happened to look at all your questions (you've been a pretty faithful customer!), and I think I noticed that you didn't rate any of the answers. So the good news is, I guess I shouldn't take it personally! Still, I wondered if you knew about the ratings and had left so many responses unrated by design. regards, mathtalk-ga```
 ```In file ExamApps.java: // Program to manage the grades of students in a course. public class ExamsApp { public static void main(String[] args) { Exams ex = new Exams(); ex.findSumAndCount(); System.out.println("Average score for class is " + ex.average); System.exit(0); } } In file Exams.java: // Program to manage the grades of students in a course. import javax.swing.JOptionPane; public class Exams { // Data fields { public double average; private double average_temp; private int sum; //sum of scores private int count; // count of scores private int sum_temp; private int count_temp; // methods public static int readInt(String prompt) { String numStr = JOptionPane.showInputDialog(prompt); return Integer.parseInt(numStr); } // preconditions: count and sum are zero // postconditions: data field sum stores the sum of scores // data field count stores the count of scores public void findSumAndCount() { int num; int score; int SENTINEL = -1; //sentinel value num = readInt("Enter number of students"); for (int i = 0; i < num; ++i) { sum_temp = 0; count_temp = 0; score = readInt("Enter student " + i + " 's first grade or " + SENTINEL + " to stop"); while (score != SENTINEL) { sum_temp += score; sum += score; // add current score to sum count_temp++; // increase count by 1 count++; // increase count by 1 System.out.println("score: " + score); score = readInt("Enter next grade or " + SENTINEL + " to stop"); } average_temp = findAve(sum_temp, count_temp); System.out.println("Average score for student " + i + " is : " + average_temp); if (average_temp >= 90) { System.out.println("Average score for student " + i + " is A " ); } else if (average_temp >= 80) { System.out.println("Average score for student " + i + " is B " ); } else { System.out.println("Average score for student " + i + " is C, D, or F -- who cares... this student fails! " ); } } average = findAve(sum, count); } // precondition: sum and count are defined // postcondition: Returns the average score public double findAve(int sum, int count) { double average; // average score if (count > 0) average = (double) sum / (double) count; else average = 0; return average; } }```