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
9 ptsCLASS (Question 2, 9 points). Write the complete Thermostat class, which models a heating thermostat. The class must satisfy the following specification. A Thermostat object keeps track of a target temperature, the most recent temperature reading, and whether the heater is currently running. It has the following public members: Thermostat(int target) — constructs a thermostat with the given target temperature, an initial reading equal to the target, and the heater off. void setTarget(int target) — changes the target temperature. The heater's state is not changed by this method. void update(int reading) — records reading as the most recent temperature. If the reading is more than 1 degree below the target, the heater turns on. If the reading is more than 1 degree above the target, the heater turns off. Otherwise the heater's state is unchanged. (This one-degree band prevents the heater from switching on and off repeatedly near the target.) boolean isHeating() — returns true if the heater is currently running. int getReading() — returns the most recent temperature reading. For example, with a Thermostat constructed at target 68: update(70) leaves the heater off; update(66) turns it on; update(67) leaves it on (67 is within one degree of 68); update(70) turns it off.
A. Write the complete Thermostat class, including all instance variables, the constructor, and all methods.