//----------------------------------------------------------------------
// The GradeBook class
//
// A gradebook must have a "course name".
//----------------------------------------------------------------------
import java.util.Scanner;
public class GradeBook {
private String courseName;
// constructor initializes courseName
public GradeBook(String name) {
courseName = name;
}
public void setCourseName(String name) {
courseName = name;
}
public String getCourseName() {
return courseName;
}
public void displayMessage() {
System.out.printf("Welcome to the grade book for\n%s!\n\n", getCourseName());
}
// determine class average based on 5 grades entered by user
public void determineClassAverage() {
// create Scanner to obtain input from command window
Scanner input = new Scanner(System.in);
int total; // sum of grades entered by user
int gradeCounter; // number of the grade to be entered next
int grade; // grade value entered by user
int average; // average of grades
int gradeNumber; // number of grades to be entered
int gradeMax = 0; // maximum of all grades
// initialization phase
total = 0;
gradeCounter = 1;
Scanner grades = new Scanner(System.in);
System.out.println("Please enter the number of grades");
gradeNumber = grades.nextInt();
// processing phase
while (gradeCounter <= gradeNumber) { // loop based on user input
System.out.print("Enter grade " + gradeCounter + ": "); // prompt
grade = input.nextInt(); // read grade from user
total = total + grade; // add grade to total
gradeMax = Math.max(gradeMax, grade); // find Max Grade
gradeCounter = gradeCounter + 1; // increment counter by
}
// termination phase
average = total / gradeNumber;
System.out.printf("\nTotal of all gradeNumber grades is %d\n", total);
System.out.printf("Class average is %d\n", average);
System.out.printf("Class Maximum is %d\n", gradeMax);