# Lab 4: Writing a Class

### Objective

To work on coding a class based off a UML diagram

For this lab, you will be writing the Java code for the class that you made the UML diagram for last lab. Pull up your diagram and base the Java class off of that.

A few notes on the implementation of the methods:

• The constructor should set the student's name based on the parameters. The credits and GPA should be set to 0. The ID should be set to the next available ID. The next available ID should then be incremented by one. Because it's static, each new student object shares this value, so they should all get unique IDs. You should initialize the next ID to 1 where it's declared (not in the constructor).
• The method to add a course should factor the grade into their GPA. To do that, weight the student's current GPA by their old number of credits, and the grade from the new course by the number of credits. For example, imagine a student's current GPA is 3.2, and they have 60 credits. If they get an A- in a 3 credit course, then their new GPA is calculated as:

$\Large \frac{3.2 \times 60 + 3.7 \times 3}{60 + 3}$

The 3.7 comes from the number equivalent to an A-. You can get the list of these values from this page.

It should then add the courses credits into the student's total. If the student has 60 credits and adds a 3 credit course, then they now have 63.

• The method to print a report should print all of the student's details to the screen in a readable way. The format is up to you.
• The method which determines if the student can graduate should check that the student has at least 120 credits and has a GPA of at least 2.0. If so, they can graduate; if not, not.

### Testing

You can use the Main.java file to test your program. You might have to change your method names slightly to work with this (but please do so, cause that's how I'll grade your lab).

Here is an example run:

\$ java Main
Alice, Johnson	1	0.00	0
Bob, Williams	2	0.00	0
Claire, Smith	3	0.00	0

Alice, Johnson	1	2.28	124
Bob, Williams	2	2.36	122
Claire, Smith	3	2.16	117