Write a class named studentgrades the constructor of


Write a class named StudentGrades. The constructor of StudentGrades should accept an array of student grades as its argument.

The StudentGrades class needs to have an instance variable of array type to store the student grades and a met.hod(getAverage) that retums1 the student's average grade. If any grade in the array is less than zero or greater than 100, the class should throw an IllegalArgumentException.

When you throw the exception, pass in a message to indicate which array element has an invalid grade and what the invalid grade is. Whoever catch the exception can use the getMessage( ) method to receive it.

Write a test program that creates two StudentGrades object, each takes in an array of valid grades and an array of invalid grades. Your test program should show that the StudentGrades class will throw an IllegalArgumentException when the array contains any invalid grade.
Given two arrays as follow:
double[] badGrades = {66.3, 76.7, 333.0, 98.0. 19.0 },
double[] goodGrades = {77.5, 86.7. 98.0, 91.0, 96.0 };
A sample output of the program is as follow:
D:'MyJava>java TestStudentGrades Invalid grade found in bad array.

element grades[2]: invalid grade is: 333.0 The average of the good array is 89.84

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write a class named studentgrades the constructor of
Reference No:- TGS01528637

Now Priced at $10 (50% Discount)

Recommended (95%)

Rated (4.7/5)