Menu

(Solved) : Using Bluej Write Scratch Class Called Heater Represents Adjustable Thermostat Follow Deta Q43962711 . . .

USING BLUEJ:

You will write from scratch a class called Heater thatrepresents an adjustable thermostat. Follow the detailed stepsbelow. 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 tofollow the instructions below.

  1. Create a new BlueJ project named LastName-heater using yourlast name.
  2. Create a class named Heater
    • At the top of the source code for Heater, add documentationlike 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 fieldusing standard naming conventions, e.g., getTemperature andsetTemperature for the temperature field. You should add a total of8 methods from this step.
    • Whenever you add a new method, include a documentation blockthat describes what the method does. For example:
      /**
      * @return current temperature of the heater
      */
    • Modify the setIncrement method so that it does not allow anegative value for the increment. Print an error message if thevalue 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, andtemperature to 50.
    • The second constructor takes 4 parameters and uses them toinitialize the fields temperature, minimum, maximum, andincrement.
    • Be sure to add a javadoc documentation block for eachconstructor.
  6. Define a method named warmer. This method takes no parametersand 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 messageand do not raise the temperature. For example:
    • If temperature=50, increment=3, and maximum=100, after a callto the warmer method, temperature will be 53.
    • If temperature=98, increment=3, and maximum=100, after a callto the warmer method, temperature is still 98 and an error messageis printed.
  7. Define a method named cooler. This method takes no parametersand 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 messageand do not lower the temperature.
  8. Adhere to Java style guidelines as described in AppendixJ.
  9. Test your code thoroughly! (Don’t wait until this step – youshould 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

Expert Answer


Answer to USING BLUEJ: You will write from scratch a class called Heater that represents an adjustable thermostat. Follow the deta…

OR