Inheritance
Method Overriding
Write a program that will compute and display the final grades for a list of students. A student's final grade is determined from the scores obtained in the class exams. Each student in the class may be given a different number of exams as determined by the instructor. The final grade is determined by the average of the scores in all the exams given.
This program is an enhancement of a previous exercise that did the same. However, this exercise will additionally provide for assigning a CR or NCR (Credit or No Credit) grade.
For each student, the program will input student id, name, the number of exams given and scores in each of the exams.
Additionally, it will input the grade type: "Letter" or Credit. The grade type of Letter will indicate that student will receive a grade of A, B, C, D, or F. The grade type of Credit will indicate that the student will receive a grade of CR or NCR.
The scores in each of the exams will vary from 0 to 100. Each exam will carry the same weight. The final grade will be computed by taking the average of the scores in all the exams given (i.e. by adding the scores in all the exams and dividing it with the number of exams given). The final grade will be assigned depending upon the percentage of total points in the exams given as follows:
A – 90 to 100%
B – 80 to 89%
C – 70 to 79%
D – 60 to 69%
F – 0 to 59%
Additionally, for a grade type of Credit, the grade will be determined as follows:
If the student qualifies for a C or better grade, the student will be assigned a CR (Credit) grade. Otherwise, the student will be assigned an NCR (No Credit) grade.
Instructions
Use a String variable for keeping final grade.
Use a String variable for keeping grade type.
Comparing Strings
For comparing two Strings for equality, use one of the following two String methods:
equals
equalsIgnoreCase
For this assignment create the following classes.
Student class
Create a class Student that provides the following:
Instead of rewriting this class, you may copy the contents of the same class from a previous exercise.
StudentExt class.
Create a class StudentExt that extends the class Student above. This class will extend the class Student in order to provide additional functionality for assigning a CR or NCR grade.
The class will provide the following:
TestStudentExt class
Write a class TestStudentExt containing the main method. The method main will do the following:
You may do this in a number of ways including the following:
Method I.
Create seven empty Strings, outA, outB, outC, outD, outF, outCr, outNcr. Use the String outA for storing output relating to A students; use String outB for storing output relating to B students; etc. Use the object accessor methods to access object values as needed. At the end, prepare a String out that concatenates all the above seven Strings. Then display the String out.
Method II.
Create a String array out of 7 Strings. Use out [0] for accumulating output relating to A students, out[1] for B students etc. Write a static method displayRestult to display output. Call the static method displayResult and pass it the array out.
displayResult
For method II above, write a static method displayResult. This method will receive a String array and display the contents of all elements of the String array one by one. Here is a proposed header for the method:
public static void displayResult (String [ ] s)
{
}
It is suggested that you use method II.
You may use the class TestStudent from a previous exercise and modify it to create this class TestStudentExt.
Input
Use the following test data for input.
1, John Adam, 3, 93, 91, 100, Letter
2, Raymond Woo, 3, 65, 68, 63, Letter
3, Rick Smith, 3, 50, 58, 53, Letter
4, Ray Bartlett, 3, 62, 64, 69, Letter
5, Mary Russell, 3, 93, 90, 98, Letter
6, Andy Wong, 3, 89,88,84, Letter
7, Jay Russell, 3, 71,73,78, Letter
8, Jimmie Wong, 3, 70,77,72, Letter
9, Jackie Chan, 3, 85,89,84, Letter
10, Susan Wu, 3, 80,88,84, Letter
11, Bruce Lee, 4, 74, 79, 72, 75, Credit
12, Chuck Norris, 5, 63, 64, 62, 60, 68, Credit
13, Jet Li, 3, 85, 83, 89, Credit
14, Jessica Lauser, 3, 82, 84, 87, Letter
15, Mahnoosh Nik-Ahd, 2, 98, 99, Letter
In the above data, for the first entry, id is 1, name is John Adam, exam scores are 93, 91, 100 and grade type is letter grade.
Output
1 John Adam (A)
5 Mary Russell (A)
15 Mahnoosh Nik-Ahd (A)
6 Andy Wong (B)
9 Jackie Chan (B)
10 Susan Wu (B)
14 Jessica Lauser (B)
7 Jay Russell (C)
8 Jimmie Wong (C)
2 Raymond Woo (D)
4 Ray Bartlett (D)
3 Rick Smith (F)
11 Bruce Lee (CR)
13 Jet Li (CR)
12 Chuck Norris (NCR)
The method findGrade below over rides the parent method findGrade. Internally, it also calls the parent method findGrade for finding the student's letter grade. On return from the parent method, in the case of a gradeType of "CR", it reassigns the grade to be CR or NCR depending upon the students letter grade as described below:
For a gradeType of "Credit", if the student's letter grade is A, B, or C, it reassigns the grade to be CR and otherwise (for a letter grade of D or F) it reassigns it to be NCR.
public String findGrade ( )
{
String grade = super.findGrade ( );
if (gradeType.equalsIgnoreCase ("Credit"))
{
if ( (grade.equalsIgnoreCase ("A")) ||
(grade.equalsIgnoreCase ("B")) ||
(grade.equalsIgnoreCase ("C")))
grade = "CR";
else
grade = "NCR";
}
return grade;
}