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
9 ptsCLASS (Question 2, 9 points). Write the complete Coupon class, which models a discount coupon that may be used a limited number of times. The class must satisfy the following specification. Coupon(String code, double percentOff, int uses) — constructs a coupon with the given code, the given percentage off (a value from 0.0 to 100.0), and the given number of remaining uses. String getCode() — returns the coupon's code. boolean isUsedUp() — returns true if the coupon has no uses remaining. double applyTo(double price) — if the coupon has at least one use remaining, reduces the remaining uses by one and returns the discounted price; otherwise returns price unchanged. A coupon with percentOff of 25.0 applied to a price of 80.00 returns 60.00. String toString() — returns a string of the form "SAVE20 (20.0% off, 3 left)" using the coupon's code, percentage, and remaining uses. For example, a Coupon constructed with ("SAVE20", 20.0, 2) returns 80.0 from applyTo(100.0), then 40.0 from applyTo(50.0), and then 30.0 from a third call to applyTo(30.0), because the coupon is used up.
A. Write the complete Coupon class, including all instance variables, the constructor, and all methods.