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.
final variable
Constructor
Object state vs behavior
Why a static method cannot use instance variables
Writing a class from a specification
toString
Precondition
Local variable
Object reference aliasing
Instance variable default values
Immutability by design
Class definition
Short answer 1. Define or explain: Encapsulation
3 ptsShort answer 2. Define or explain: Default constructor
3 ptsShort answer 3. Define or explain: Accessor (getter)
3 ptsShort answer 4. Define or explain: Scope
3 ptsFree response
9 ptsCLASS DESIGN (Question 2, 9 points). Write the complete Bottle class, representing a bottle of liquid. The constructor takes a double capacity in milliliters (≥ 0); a newly constructed bottle is filled to capacity. public double updateAmount(double used) — removes used mL from the bottle (precondition: 0 < used ≤ amount remaining). If the removal would leave the bottle below 25% of its capacity, the bottle is immediately refilled to capacity. The method returns the amount remaining after the update. Examples: a 1000 mL bottle after updateAmount(400.0) returns 600.0; then updateAmount(100.0) returns 500.0; then updateAmount(300.0) leaves 200 mL — below 250 mL (25% of 1000) — so the bottle refills and 1000.0 is returned. A 40 mL bottle after updateAmount(30.0) returns 10.0 (exactly 25% — not below — so no refill); then updateAmount(1.0) leaves 9 mL < 10 mL, so it refills and returns 40.0.
Write the complete Bottle class: instance variables, constructor, and updateAmount, meeting all specifications and conforming to the examples.