CS 1713 Introduction to Computer Science -- Spring 2001
Practice Problem on Classes
Consider the following Student class
(this class is also used below in the practice problem
on interfaces):
public class Student {
private String name; // In the form "LastName, FirstName"
private double GPA; // grade point average
private int collegeClass; // 1 = FR, 2 = SO, 3 = JR, 4 = SR, 5 = GR
public Student(){} // some reasonable constructor
public double getGPA() {} // return the GPA
// ...
}
Answer the following questions:
- Write a reasonable constructor that has three parameters
corresponding to the three data fields.
- Write code in a separate class or in a main
method that will create student classes with the following data
for name, GPA, and collegeClass:
- "Blow, Joe", 3.4, 2
- "Bonkers, Bruce", 2.9, 3
- "Nutcase, Nancy", 3.7, 2
- Etc.
- Write code for the getGPA method and show how
to invoke it for the first student above (Joe Blow).