## CS 1401 Assignment #12

Date Assigned: Monday, April 24, 2006 or Tuesday, April 25, 2006.

Due Date: correspondingly, Monday, May 1, 2006, or Tuesday, May 2, 2006, before the beginning of your lab section.

Goals: to learn how to use arrays of objects.

Points: This assignment is worth a total of 20 points. No late assignments will be accepted, but credit will be given for partially completed assignments turned in on time.

Assignment: This assignment is a continuation of Assignment 11 about computing GPA in Computer Science. As in that assignment, for each student, all the classes that this student took and the corresponding grades are stored in a file. The first line of this file contains the student's name; every other line contains the catalog number of the class and the grade that the student received in this class. For example, for John Johnson, this file may take the following form:

```John Johnson
MATH 3111 A
CS 1401 B
CS 3195 A
```
To compute the GPA, we must take all the grades in CS classes, multiply each grade by the number of hours in the corresponding class (the number of hours is the second digit of the class number), add the overall number of points, and divide this number by the total number of hours in CS classes. For example, for John Johnson, we have:
• The first class is a Math class, not a CS class, so it produces no CS points.
• The second class is a CS class. The second digit in its number (1401) is 4, so this is a 4-credit class. John Johnson earned 3 points (corresponding to B) for this 4-credit class, so the total number of points for this class is 3 x 4 = 12 points.
• The third class is also a CS class. The second digit in its number (3195) is 1, so this is a 1-credit class. John Johnson earned 4 points (corresponding to A) for this 1-credit class, so the total number of points for this class is 4 x 1 = 4 points.
Overall, the student earned 12 + 4 = 16 points, and he took 4 + 1 = 5 credit hours -- so his GPA is 16 / 5 = 3.2.

The difference with the previous assignment is that instead of two arrays of numbers, we will now have arrays of objects.

Define a Java class ClassGrade; each object of this Java class must have a field subject, a field courseNumber (you may want to make it a string), and a field grade (a character). For example, for the object corresponding to John Johnson taking CS 1401, the field subject should contain CS, the field courseNumber should contain 1401, and the field grade should contain B. Use encapsulation; in other words, make sure that these fields are private and are only accessible via methods.

Write an application that:

• asks the user for a name of the file where the grades are stored;
• reads the data, from the file, into the variable studentName and into an array classes of type ClassGrade; at the same time, the program should compute the overall number of CS classes that a student took.
• computes and displays (after displaying the student's name):
• the overall number of CS credit hours;
• the overall number of CS points;
• the student's GPA in major.
Use a for-loop to compute the overall number of CS credit hours and the overall number of CS points.

Deliverables: as announced in the labs.