Question: Tracking Grades A teacher wants a program to keep track of grades for students and decides to create a student class for his programas follows:



Tracking Grades A teacher wants a program to keep track of grades for students and decides to create a student class for his programas follows: Each student will be described by three pleoen of data: hisher nome, hisher score on test 1, and his/her score on test #2 There will be one constructor, which will have one argument--the name of the student, There will be three mothods: geName, which will return the student's name ImpwGrades, which will prompt for and read in the student's test grades and getAverage, which will compute and return the student's average 1. File Student Server contains an incomplete definition for the Student class Save it to your directory and complete the class definition as follows: Declare the instance data (nume, score for test, and score for test2) b. Create Scanner object for reading in the scores Add the missing method headers d Add the missing method bodies 2. File Grades av contains a shell program that declares two Student objects. Save it to your directory and to the inparrader method to read in each student's test scores, tune the gallery method to find the average Print the average with the student's name, .. "The average for Joel B7 You can use the geName method to print the student's name 3. Add statements to your Grades program that print the values of your student variables directly. System.out.println("Student : + students This should compile, but notice what it does when you nothing very useful When an object is printed, Java looks for String method for that object. This method must have no preters and most retum String, trucha method has been defined for this object, it is called and the stringit retums is printed otherwise the default Strong method, which is inherited from the Object class, is called; it simply returns a unique hexadecimal Identifier for the object such as the ones you saw above Add toString method to your Student class that restring containing the studen' name and test scores, Nanet Joe Test Test21 91 Add a toString method to your Student class that returns a string containing the student's name and test scores, eg: Name : Joe Testi: 85 Test2: 91 Note that the toString method does not call System.out.printlnt just returns a string Recompile your Student class and the Grades program (you shouldn't have to change the Grades program...you don't have to call toString explicitly). Now see what happens when you print a student object-much nicer // Student.java Define a student class that stores nane, score on test 1, and // score on test 2. Methods prompt for and read in grades, // compute the average, and return a string containing student's info. 17 import java.util.Scanner; public class Student //declare instance data 1/--- //constructor //-- public Student (String studentName) I 1/add body of constructor } 17--- 1/inputGrades: prompt for and read in student's grades con testl and test 2. 7/0se name in prompts, e.g., "Enter's Joe's score for testim 1/----- public void input Grades) //add body of input Grades //-- //inputGrades: prompt for and read in student's grades for testi and test2 1/Use name in prompts, e.g., "Enter's Joe's score for test1". //--- public void inputGrades() 1/add body of inputGrades //--- 1/getAverage: compute and return the student's test average Hadd header for getAverage Hadd body of getAverage //-- //getName: print the student's nane 1 // - add header for print Name 1/add body of print Name
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
