Your cart is currently empty!
For this lab we will be looking at static, or class variables. Remember, instance variables are associated with a particular instance, where static variables belong to the class. If there are n instances of a class, there are n copies of an instance variable, but exactly one copy of a static variable. Underlined items are…
For this lab we will be looking at static, or class variables. Remember, instance variables are associated with a particular instance, where static variables belong to the class. If there are n instances of a class, there are n copies of an instance variable, but exactly one copy of a static variable. Underlined items are static members of the class.
Student
– name: String
– gpa: double
– major: String
– totalStudents: int
– totalGPA: double
– totalCompSciMajors: int
– totalCompSciGPA: double
+ Student(name: String, gpa: double, major: String)
+ getName(): String
+ setName(name: String)
+ getGPA(): double
+ setGPA(gpa: double)
+ getMajor(): String
+ getStudentAvg(): double
+ getCompSciAvg(): double
+ toString(): String
+ equals(other: Object): boolean
o Student Name: <name>, Major: <major>, GPA: <gpa>
Driver Output
All students:
Student Name: Eva, Major: CompSci, GPA: 3.5
Student Name: Ahmed, Major: CompSci, GPA: 4.0
Student Name: Shaina, Major: EE, GPA: 3.5
Student Name: Megan, Major: Accounting, GPA: 3.0
Student Name: Antonio, Major: CompSci, GPA: 3.0
Student Name: Jim, Major: Business, GPA: 1.5
Student Name: Morgan, Major: Architecture, GPA: 3.5
Testing equals methods. Does Eva equal Ahmed?
They are not the same.
Does Antonio equal Antonio? They are the same.
Testing static variables. All Students avg = 3.14
All CompSci Students avg = 3.50
Time to set all gpa values to 3.0.
If done correctly, both averages should be 3.0.
All Students avg = 3.00
All CompSci Students avg = 3.00
Time to set all gpa values of CompSci Students to 4.0. If done correctly, both averages should be different.
All Students avg = 3.43
All CompSci Students avg = 4.00