Class Creation unit test
A test on this unit alone, marked as a percentage and a letter grade — for the test your class is actually sitting, rather than for May. Answer everything, then submit once: seeing the answer to question 3 before attempting question 4 makes the final percentage meaningless.
Accessor (getter)
Object state vs behavior
Class definition
Local variable
Mutator (setter)
toString
equals for your own class
Why instance variables are private
Default toString
Method decomposition
Scope
Accessing a private field of another object of the same class
Short answer 1. Define or explain: public vs private
3 ptsShort answer 2. Define or explain: final variable
3 ptsShort answer 3. Define or explain: Postcondition
3 ptsShort answer 4. Define or explain: Object reference aliasing
3 ptsFree response
6 ptsThis course has no free-response prompt tagged to this unit, so one from elsewhere in the course is used. It is still worth writing — the skill transfers.
A class Roster stores student scores in a private field private ArrayList<Integer> scores. Write two methods for Roster.
public double average() — returns the average of all scores as a double, or 0.0 if the list is empty.
public int removeBelow(int cutoff) — removes every score strictly less than cutoff from the list and returns how many scores were removed. The order of the remaining scores must be preserved. Write the two methods. Assume all values in scores are non-null.