home—info—lects—labs—exams—hws
tutor/PIs—Object120 + its docs—java.lang docs—java.util docs
hw06
non-static methods
converting students
Due Oct.22 (Fri) 16:00;
submit on WebCT and
bring hardcopy to class Friday morning or under my office door by
Friday afternoon.
For this homework,
we will just
modify hw05—Modifying objects: Student gpas so that it is object-oriented:
that is, we'll convert the static functions into non-static methods.
We will also need create our own equals and toString,
instead of relying on the ones provided in Object120.
-
Create a new project for hw06, and copy/paste in
your existing hw05 Student.java.
(You can also use the
provided hw05 solution.)
Use BlueJ's search/replace feature to change all occurrences
of Student to
something like “Student_v2”
or “Student2”
or “Pupil”.
- (3x3pts)
Go through your code, and re-write
changesetMajor
so that it is non-static. This requires modifying test cases, too.
Make sure everything still runs.
Then, do the same for getGPA and recordGradeClass.
(We don't change enrollStudent or testStudents
— why are they left as static methods?)
- (3pts)
Do not have your class extends Object120.
(Note that this change requires updating some code to compile:
equals still exists, but the built-in version
is object-oriented — that is, non-static.)
At this point you should be able to compile and run, but
your test cases may not pass; we'll address that in the last two steps.
- (4pts)
Write toString(), so that we can see our failing tests better.
- (4pts)
Write
equals so that
it compares all fields of two Students.
- (5pts)
Write an interactive function testStudentInteractive,
as described on lab08a.
home—info—lects—labs—exams—hws
tutor/PIs—Object120 + its docs—java.lang docs—java.util docs