home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
hw06
non-static methods
converting students
Due Oct.18 (Thu) in class;
submit on D2L and bring hardcopy to class.
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 setMajor
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.
- Tentative: this task subject to update.
(4pts)
Write a function
looksEquals so that
it compares all fields of two Students.
Change your assertEquals.
- Tentative: this task subject to mentioning Scanner
in lecture.
(5pts)
Write an interactive function testStudentInteractive,
which:
-
(a) prompts the user for a name and major,
(b) creates a student object appropriately;
(c) prints out that student object to the screen.
- Then, it does the following, exactly four times in a row1:
(a) Prints the student's name and their current gpa,
(b) asks the user to enter a grade and # of credit-hours;
(c) updates the student's gpa and prints it.
1
Yes, you will have the exact same lines copy/pasted several times.
We'll see how to write loops by the next homework,
which would let us fix this.
↩
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs