Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Grades class that in the constructor accepts a list of integer grades a

ID: 3535628 • Letter: C

Question

Create a Grades class that in the constructor accepts a list of integer grades as parameters in which the number of grades in the list can vary from user to user. The Grades class must provide: -- a Max method that returns the maximum grade value found in the list as an integer -- a Min method that returns the minimum grade value found in the list as an integer -- an Average method that returns the numerical average of all grades in the list as a float -- a ToString method that prints out the letter grade (A, B, C, D, and F) of the average of the grades.

Explanation / Answer


public class GradeRange

{

//-----------------------------------------------------------------

// Creates an array of Grade objects and prints them.

//-----------------------------------------------------------------

public static void main (String[] args)  Note: driver.

{

Grade[ ] grades = // creating an array of pointers to grades followed by

{ // the actual creation of 12 grade objects…. (Initializer list)

new Grade("A", 95), new Grade("A-", 90),

new Grade("B+", 87), new Grade("B", 85), new Grade("B-", 80),

new Grade("C+", 77), new Grade("C", 75), new Grade("C-", 70),

new Grade("D+", 67), new Grade("D", 65), new Grade("D-", 60),

new Grade("F", 0)

}; // Note: could have read these in from a file too


for (Grade letterGrade : grades) // Here, using iterator form of the ‘for’, we

System.out.println (letterGrade); // are printing grades using Grade toString

} // end main() // Can see that after initializing the array

} // end class // grades, we are merely printing them out.