Question: The objectives of this lab are: Practice designing equality between objects and implementing it . Practice using references properly. Write JUnit tests to verify that

The objectives of this lab are:
Practice designing equality between objects and implementing it.
Practice using references properly.
Write JUnit tests to verify that implementation matches the specification.
The Thermostat interface
In this lab, you will implement a class that represents a simple thermostat, and a monitor that observes several thermostats and alerts if too many of them have been cranked up too high. Through this, you will practice designing equality, and using references appropriately.
A thermostat is represented by the Thermostat interface. One Thermostat -type object represents one physical thermostat. This interface should contain the following methods:
A method to retrieve its model number: String getModelNumber().
A method to get the temperature in degrees Kelvin that the thermostat is set to: double getSetTemperature().
A method that increases the set temperature for the thermostat (by an implementation-dependent amount): void increaseSetTemperature().
A method that decreases the set temperature for the thermostat (by an implementation-dependent amount): void decreaseSetTemperature().
Create the above interface, and document its specifications as detailed above.
Design JUnit tests that verify these specifications for an implementation called SimpleThermostat .
Implement the Thermostat interface in a SimpleThermostat class. Leave all the methods blank for now, but document them properly. The specifications for this implementation (beyond what the interface specifies) are:This class represents the set temperature in celsius. It cannot have a blank model number, or be set at any time to a temperature greater than 50 degrees celsius.
This class should have a single public constructor that takes the model number and the initial set temperature in celsius as its only arguments, in that order. Invalid values should cause this constructor to throw an IllegalArgumentException .
The amount by which the temperature of this thermostat can be increased or decreased at a time is 0.1 degrees celsius.
If you do not know, the temperature in degrees kelvin is simply the temperature in celsius plus 273.15.
Two thermostats are the same if they have the same model numbers (case-sensitive), and their temperatures are less than 0.01 degrees celsius apart. Implement this notion of equality in this class. Do not forget to override hashCode as well!
For each method to be implemented in the SimpleThermostat class: design and write all JUnit tests to verify its specification, then complete the implementation and run the tests. Proceed in this "write tests -> implement method -> run tests" to complete the class. Follow the directions in Lab 1 to place the test files correctly in your project.
Comment out your earlier implementation of equality and hash code, and replace with a new one: two thermostats are the same if they have the same model number (case-sensitive) and if their temperature values when rounded to two decimal places are the same (e.g.25.371 and 25.374). Write tests for this new implementation (preserve your earlier code and tests in comments).
You should continue to work with code above that has the second notion of equality for this part.
Incorporate the provided NaiveTemperatureMonitor class into your project. Your project should compile correctly.
The provided class has several...flaws/undesirable qualities:
This class makes a common mistake in design: it defines new public methods. Good design dictates that all public methods in a class (other than the constructor) should come from some interface. Create an interface TemperatureMonitor and retrofit the provided NaiveTemperatureMonitor class so that it implements this interface to remove this flaw.
This class is almost completely undocumented. One has to read and understand the code to know what it is doing. Document the interface and the class to remove this flaw. It is important to remember that the interface is more general-purpose, so do not put implementation-specific details or constraints in it!
The provided NaiveTemperatureMonitor class has a flaw: sometimes it reports too much heating even if only one physical thermostat is cranked up! Write one or more tests that should pass on a flawless implementation, but fails on the given one.
Fix the implementation so that this flaw is removed. Your tests should now pass.
Write detailed tests for every implemnetation as much as possible covering every scenarios, not just one or two basic tests.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!