1. Develop a simple grade transcript program. We will have two classes, a Course class representing an individual course that a student has taken and a Transcript class that will combine several Course objects and calculate an overall grade point average (GPA). We will also have two test classes, one for the Course class and one for the Transcript class.
2. Design and build a Course class. This will have three instance variables. There will be a courseID variable that will hold the course identification number. We will use the standard State of Florida numbering system (this course is "COP 2253"). We will have a letterGrade variable that will hold the assigned course grade. We will also have a numberGrade variable that will hold a numeric equivalent to the letterGrade. The class should have a constructor, accessors for the instance variables, a method to compute the numeric grade, a method to update the grade, and a method to convert the state of the object to a string. Using the UML, the class diagram looks like this:
Course
- courseID : String
- letterGrade : String
- numberGrade : double
+ Course( String, String )
+ getCourseID( ) : String
+ getLetterGrade( ) : String
+ getNumericGrade( ) : double
- computeGrade()
+ updateGrade( String )
+ toString( ) : String
a. The constructor will assign the first parameter to the variable courseID and the second parameter to the variable letterGrade. The constructor will then call the method computeGrade() to convert the letter grade to a numeric equivalent and store it in the variable numberGrade.
b. The class will have three accessor methods getCourseID(), getLetterGrade(), and getNumericGrade() that will return the value of each respective instance variable.
c. The method computeGrade() handles the conversion of the letter grade to a numeric equivalent and saves it in the instance variable numberGrade. The letter grades will range from "A" to "F". The letter grades have numeric values ranging from 4.0 for an "A" to 0.0 for an "F". We may also have a "+" or a "-" after some letter grades. The "+" can be appended to B's, C's, and D's and increases the value of the letter grade by 0.3 points. A "-" appended to A's, B's, and C's decreases the value of the letter grade by 0.3 points. There are no "A+", 'D-", "F+" or "F-" grades. Use the switch statement to determine which of the set of letter grades we have. Use the if { ... } else { ... } construction to handle the modification of the basic numeric grade with the "+" and "-' modifiers. There will be 11 possible valid grades.
d. The class will have a method updateGrade(String) that takes a new letter grade value as a String parameter, and updates the letterGrade and numberGrade variables accordingly. NumberGrade can be updated by calling the computeGrade () method as done in the constructor. Note that we can call methods of a class from within the class; in this case, we do not use the dot (.) operator. Methods which are useful to other methods are called utility methods, and do not need to be public if they will only be called from within the class. In this case, computeGrade() is a utility method.
e. The method toString() allows us to access the state of the object in a printable or readable form. It converts the variables to a single string that is neatly formatted. Look at pages 23 and 24 of the text for a discussion of escape sequences. These are characters that you can insert into your strings and, when printed, will format the display neatly. You can insert an escape sequence for the tab character and get a tabular form when printing. This tab character is '\t'. Your class will have a toString() method that concatenates courseID, letterGrade, and numberGrade separated by tab characters and returns this new string. When you try to print an object, the toString() method will be implicitly called, which in this case, will print a string that will look something like:
COP 2253 A- 3.7
3. Build a Transcript class that will store information about the courses taken (Course Objects) by one specific student. It should include a studentID and studentName. It should also include an ArrayList (You must use an ArrayList, not an array) to hold information about each course (course object) that the student has completed.
4. Build a TranscriptTest class to test your application. Your test class should not require any interaction with the user. It should verify the correct operation of the constructor and all methods in the Transcript class.
Specific Requirements for the Transcript Class
1. The transcript class should have a constructor with two parameters. The first is an integer containing the student's ID and the second is a String containing the student's name.
2. There should be a method to allow the addition of a course to the transcript. The two parameters for the addCourse method will be (1) the courseID and (2) the letterGrade.
3. There should be a method to allow the updating of a course already in the transcript. Notice that updating a course means changing the letter grade. The parameters for the updateCourse method are also (1) the courseID and (2) the letterGrade. Notice that the updating of a specific course requires a search through the ArrayList to find the desired course. Anytime a search is done, the possibility exists that the search will be unsuccessful. It is often difficult to decide what action should be taken when such an "exception" occurs. Since exception handling is not covered until later in this textbook, we will make some arbitrary decisions for this project. If the course to be updated is not found, you will take the simplest action possible and do nothing. Do not print an error message to the screen. Simply leave the transcript unchanged.
4. The transcript class needs a method called getGPA to return the student's GPA. You should implement a method called calculateGPA that will go through the array of courses and make the appropriate calculation. The calculateGPA method should never be called from outside the class, so it should be made private. Recall that the Course class maintains a numeric grade indicating GPA points.
5. There should also be a method to return information about a specific course. It should return a single String object in the same format described for the Course class:
COP 2253 A- 3.7
Again, the possibility exists that the search for a specific class will fail. In this instance, you should return a string containing a message similar to this:
COP 2253 not found.
6. The final method needed is a toString method. It should return the transcript information in a single String object. It should use the following format:
ID : 12345
Name : John Doe
GPA : 4.0
COP 2253 A 4.0
COP 3022 A 4.0
COP 3530 A 4.0
Notice that a newline character '\n' can be inserted into the middle of a string.
Ex.
int age = 30;
String temp = "John Doe \n is " + age + "\n" + " years old";
The output would be:
John Doe
is 30
years old
Notice also that the '\n' is a single character and could actually go inside single or double quotes, depending on the circumstances.
Here is a UML diagram for the Transcript class as describe above. Notice that you may add private instance variables and methods as needed. For all public methods use exactly the name given below. Remember that calculateGPA should be private.
Transcript
- courses : ArrayList<Course>
- studentID : int
- studentName : String
+ Transcript( int, String )
+ addCourse( String, String )
+ updateCourse( String, String )
- calculateGPA( )
+ getGPA( ) : double
+ getCourse( ) : String
+ toString( ) : String
Already tried:
public class Course { //Instance variable public String courseID; public String letterGrade; public double numberGrade; /* @Constructors */ public Course(String courseID, String letterGrade) { courseID = courseID; letterGrade = letterGrade; computeGrade(); } public String getCourseID() { return courseID; } public String getLetterGrade() { return letterGrade; } public double getNumericGrade() { return numberGrade; } public void computeGrade() { switch(letterGrade) { case "A": numberGrade = 0.4;break; case "B": numberGrade = 0.3;break; case "C": numberGrade = 0.2;break; case "D": numberGrade = 0.1;break; case "F": numberGrade = 0.0;break; default: numberGrade = 0; break; } } public void updateGrade(String letterGrade) { LetterGrade(letterGrade);