Project 1) This project involves creating two classes-a
Student class and a
School class. Create a Student class which should represent a typical school student. Each student has a unique student identification number, a name, a height and an address.
Student
Static Variable (aka Class variable)
-
int nextStudentId
private instance variables
String name
int age
int idNum
String address
double height
double gpa
int numberOfCLasses
int gradeLevel
Constructors
- a single paramater constructor that takes a String parameter that is used to initialize the instance variable
name.
- a double parameter constructor that takes two string parameters that are used to initialize the instance variables
name and address.
- Both constructors should use a static variable (aka class variable) to ensure that each student's variable,
idNum, is unique
Accessor and Mutator methods
- Create accessor and mutator methods for all private class variables.
Override the following Object methods
-
String toString()This method should return a comma separated String comprised of all of the instance variables
boolean equals(Object obj) This method should only return true if both idNum and name of the given object and its paramater are the same. Note: To be able to acces the parameter's instance variables such as idNum you must cast the Object parameter obj to type student as follows: ((Student)obj).idNum . Notice where the paranthesis and the dot are . You must follow this syntax because the dot operator has higher precedence than the cast operation.
School
private instance variables
-
ArrayList<Student> studentBody
methods
int numStudents(); //returns the total number of students in studentBody
int numStudentsInGrade( int gLevel) //returns the total number of students in studentBody whose gradeLevel is gLevel.
double meanGpa (int gLevel) ; // returns the mean of all the gpas in studentBody whose gradeLevel is gLevel.
void addStudent(Student s) // adds a student to student to studentBody
-
double percentPassing(int gLevel) //returns the percent of students in studentBody whose gradeLevel is gLevel. and whose gpa greater than or equal to a passing gpa. This should return a two digit double rounded to the thenths place (ie 78.2 represents 78.2 percent are passing)
boolean containsStudent(int studentId) //return true if there is a student in studentBody whose idNum is the parameter studentId
boolean removeStudent( int studentId) //removes the student whose idNum is the parameter studentId . Returns true if the student was removed. False otherwise ie invalid id parameter)
void graduate(); removes all students whose gradeLevel is 12.
- extra credit:
ArrayList<Student> topTen(int gLevel)//returns an ArrayList of Students with the ten highest gpa's in studentBody
- extra credit: double modeGpa(int gLevel) //returns the mode gpa of all students with
gradeLevel is gLevel.
- extra credit: String mostCommonName() //returns the most common name in student body or "" if there is no single most
common name