Lab 7: Student

Posted: October 6, 2009

This lab is due Friday, October 9 Tuesday, October 13 in class.

Write a class Student that can hold a student’s name and six grades (English, Math, Science, Social Studies, PE, and Art). The grades will be represented by numbers on the following scale: A = 4.00, A- = 3.70, B+ = 3.30, B = 3.00, B- = 2.70, etc.

Include the following methods (in addition to any getters and setters you need), choosing the correct return types as necessary:

  • getGPA method that will calculate and return the GPA (Grade Point Average, the mean of all six grades) for the student.
  • getCollegeGPA method that disregards all + or – parts of the grade (so a B+, B, and B- all count for 3.0) and returns the GPA.
  • setGrades method that takes six double parameters to set the grades for each of the courses stated above in the order stated above.
  • printStudentRecord method that will output the student’s name, GPA, and college GPA.

Write a TestDrive class that creates a few students, sets their names, sets six grades for each, and then calls printStudentRecord() for each of them. Decide which instance variables and methods should be public versus private, and make them so. Be prepared to defend your encapsulation decisions.

Remember to use internal method calls and the enhanced for loop if they will make your life easier.

Extra credit: Create a setGrades method that takes six Strings (such as “A-” or “C+”) and sets the grade variables correctly. You may add other methods to help if necessary.