Implement a class containing static methods.
For this lab, you will write a class called "Student". It should have the following instance variables:
It should also have one static class variable. Remember these are shared amongst all instances of a class:
It should also have the following methods:
getNextId()
which returns the
next id currently available. It then increments this field.
This way, each time the method is called, a new id is generated.getNextId
returns.A method called addCourse
which takes the
number of credits of the course (an int), and the grade the student
got in the course (a String).
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.
report()
that prints a report on the student.
This should take no parameters and return void. 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.canGraduate()
which determines if the student
can graduate. To do this, it 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.You can use the StudentMain.java file to test your program.
Here is an example run:
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 Alice can graduate. Bob can graduate. Claire CAN'T graduate.
When you are done, please submit the Java code under the assignment in Canvas.
You only need to submit the Student.java file, not the Main.java one.
Copyright © 2022 Ian Finlayson | Licensed under a Attribution-NonCommercial 4.0 International License.