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.
toString
Immutability by design
Class definition
static method
Mutator (setter)
Instance variable default values
Accessor (getter)
Encapsulation
Default toString
Precondition
Constructor
Object reference aliasing
Short answer 1. Define or explain: equals for your own class
3 ptsShort answer 2. Define or explain: Writing a class from a specification
3 ptsShort answer 3. Define or explain: Return type of a constructor
3 ptsShort answer 4. Define or explain: Calling one constructor from another
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.