Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a java class called TestGrades (TestGrades.java) and a driver program called Grade Driver (Grade Driver.java) that uses/tests the TestGrades class. Both files you create
Write a java class called TestGrades (TestGrades.java) and a driver program called Grade Driver (Grade Driver.java) that uses/tests the TestGrades class. Both files you create should follow all the documentation requirements discussed in class and listed in the Documentation Requirements.pdf file located in the top module in Canvas. ZIP both files into a zip file names Project4.zip, and submit Project4.zip to Canvas in the Project 4 link by the posted due date and time. Details are as follows: GradeDriver (a skeleton version you will complete is provided in the zip folder on Canvas) An array of TestGrades will be created of a size based on the first integer in the input file in 4.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 student's tests average of the 3 highest test scores (possibly save this information in a student's 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 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 getTests Average (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. You are to write the driver program in its entirety, except the simplified steps for file 1/0 that I have included in the very skeletal version of Grade Driver.java. GradeDriver.java and a sample in4.txt have been compressed into a folder named Project 4 Filest.zip Input from the input file and the creation of the array of TestGrades objects should be handled in a method (say getGrades) that receives a Scanner (opened in main) to the input file and returns an array of TestGrades. The basic pseudocode might be as follows: Create a TestGrades array of a size based on the first integer in the input file Repeat the following steps the size of the TestGrades number of times: Read the first name into a variable Read the second name into a variable Create and in array of 4 elements Read the next 4 input file values into the elements of the array just created Assign to the TestGrades array (at the current index) a new TestGrades object (Remember, the TestGrades constructor needs 2 Strings and an array of int, i.e. first name, second name, and the array of test scores. Return the TestGrades array The driver will also need a method that produces the specified statistics needed for output. These statistic can be passed to a method for creating the output. 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 1 in4 - Notepad Edit Format View Help File Bad Boy 20 15 32 41 Good Son 89 90 98 94 Dr. Chu 96 75 100 99 Lone Star 85 91 78 100 Tom Tom 50 60 70 80 Sally Soso 78 67 72 75 Bump Onalog 55 63 58 49 import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.Scanner; /** Add appropriate documentation here */ public class GradeDriver{ /** * Add appropriate documentation here public static void main(String[] theArgs) { 1/ Declare needed variables here = // The following should be good enough to open 1/ your files for I/O 1/ Use input for your input file and output for 1/ your output results file Scanner input = null; PrintStream output null; try { input = new Scanner(new File("in4.txt")); output = new PrintStream(new File("out4.txt")); } catch (FileNotFoundException e) { System.out.println("Error opening file: + e); } 1/ Fill in the operations that create, manipulate, and output the // results of the TestGrades objects here 1/ Use separate methods for reading in the data, 1/ processing the data, and output } // End of main // write your methods here // Use appropriate javadoc including proper tags for each method.L } // End of GradeDriver
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started