Answered step by step
Verified Expert Solution
Link Copied!

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.

  1. Create a new BlueJ project named LastName-heater using your last name.
  2. 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 */
  3. Add the following 4 int fields:
    • temperature
    • minimum
    • maximum
    • increment
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. Adhere to Java style guidelines as described in Appendix J.
  9. Test your code thoroughly! (Don't wait until this step - you should be testing each piece as you go.)
  10. Create a jar file of your project.
    1. From BlueJ, choose Project->Create Jar File...
    2. Check the "Include source" check box
    3. Name the file LastName-heater

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

Over the past

Answered: 1 week ago