Answered step by step
Verified Expert Solution
Question
1 Approved Answer
USING BLUEJ: You will write from scratch a class called Heater that represents an adjustable thermostat. Follow the detailed steps below. This is based on
USING BLUEJ:
You will write from scratch a class called Heater that represents an adjustable thermostat. Follow the detailed steps below. This is based on Exercises 2.93 - 2.94 (6e) / 2.92 - 2.93 (5e) in the book, but with slight modifications, so be sure to follow the instructions below.
- Create a new BlueJ project named LastName-heater using your last name.
- Create a class named Heater
- At the top of the source code for Heater, add documentation like this: /** * Heater project * Simulate the behavior of a heater (thermostat) * * Modifications: * List the modifications as you make them * * @author Your Name * @version The Date */
- Add the following 4 int fields:
- temperature
- minimum
- maximum
- increment
- Write getters (accessors) and setters (mutators) for each field using standard naming conventions, e.g., getTemperature and setTemperature for the temperature field. You should add a total of 8 methods from this step.
- Whenever you add a new method, include a documentation block that describes what the method does. For example: /** * @return current temperature of the heater */
- Modify the setIncrement method so that it does not allow a negative value for the increment. Print an error message if the value given is negative and leave the increment unchanged.
- Define two constructors for the class:
- The first constructor takes no parameters. In this constructor, initialize minimum to 0, maximum to 100, increment to 1, and temperature to 50.
- The second constructor takes 4 parameters and uses them to initialize the fields temperature, minimum, maximum, and increment.
- Be sure to add a javadoc documentation block for each constructor.
- Define a method named warmer. This method takes no parameters and raises the temperature by the value of the increment field. However, it should not allow the temperature to go above maximum. If the temperature would go above maximum, print an error message and do not raise the temperature. For example:
- If temperature=50, increment=3, and maximum=100, after a call to the warmer method, temperature will be 53.
- If temperature=98, increment=3, and maximum=100, after a call to the warmer method, temperature is still 98 and an error message is printed.
- Define a method named cooler. This method takes no parameters and lowers the temperature by the value of the increment field. However, it should not allow the temperature to go below minimum. If the temperature would go below minimum, print an error message and do not lower the temperature.
- Adhere to Java style guidelines as described in Appendix J.
- Test your code thoroughly! (Don't wait until this step - you should be testing each piece as you go.)
- Create a jar file of your project.
- From BlueJ, choose Project->Create Jar File...
- Check the "Include source" check box
- Name the file LastName-heater
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started