Write a java class called TestGrades (TestGrades.java) and a driver program called GradeDriver (GradeDriver.java) that uses/tests the TestGrades class.

GradeDriver

  • An array of TestGrades will be created of a size based on the first integer in the input file in4.txt
  • Continues to read a list of student names and their grades for 4 tests from the file: in4.txt
  • A new object will be created for each array element and filled with the input data of each student
  • Generate a report, sent to the file out4.txt, that displays:
    • The number of students in the class
    • Each student's data (all the fields described below in the details for the class TestGrades) and the students tests average of the 3 highest test scores (possibly save this information in a students test average field- its up to you)
    • The Highest student average
    • The lowest student average
    • The overall Class average

TestGrades

Fields (all private and ALL field names should begin with my- such as myFirstName, etc. Also, all fields including static field should be preceded with a Javadoc comment):

  • static int field as a counter for how many student objects have been created and set to zero in the declaration. All remaining fields are not set to any value where they are declared. These remaining fields are to be set inside the TestGrades constructor.
  • a first name field, a last name field, and an int array to store the test scores (all should be private and do not assign anything to these fields where they are declared. Assignments to the fields should only occur in the constructor and any mutator methods)

Methods (all public - no static)

  • constructor receives a first name, a last name, and an array of int containing 4 test scores. The operations in the constructor should set the student's first and last name to the received names, and increments the counter. It should then instantiate the test scores array to contain 4 elements and fills the TestGrades test scores field with the received tests.
  • accessor methods "get" - (getStudentCount, getFirstName, getLastName)
  • accessor method getTestsAverage (average of 3 highest test scores). This should return an int representing the the test scores average rounded to an int.
  • mutator method "setScore" that receives an index (representing a test number) and a test score, enforces the invariant that the test number has to be greater than 0 and less than 5 and the score has to be between 0 and 100, inclusive, and throws an appropriate exception otherwise. If no exception is thrown, it then sets the appropriate test in the grades array field. The driver will not call this method, but you should include it in the class.
  • toString method that returns a String in the form: firstname lastname [xx, xx, xx, xx] Average = xx where xx represents a test score and average

If you think you might need any other methods that would be useful based on this assignment, feel free to create and use them.

Sample Input and Execution Run:

3
Tom Tom
50 60 70 80
Sally Soso
70 80 90 100
Bump Onalog
60 70 80 90

Output:

Total number of students: 3
Tom Tom [50, 60, 70, 80] Average = 70
Sally Soso [70, 80, 90, 100] Average = 90
Bump Onalog [60, 70, 80, 90] Average = 80

Highest Student Average = 90
Lowest Student Average = 70
Overall Class Average = 80
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.