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 implementationdependent amount: void increaseSetTemperature
A method that decreases the set temperature for the thermostat by an implementationdependent 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 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 degrees celsius.
If you do not know, the temperature in degrees kelvin is simply the temperature in celsius plus
Two thermostats are the same if they have the same model numbers casesensitive and their temperatures are less than 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 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 casesensitive and if their temperature values when rounded to two decimal places are the same eg and 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...flawsundesirable 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 generalpurpose, so do not put implementationspecific 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
