Guest User

Untitled

a guest
Jan 20th, 2020
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Exercise 2.93 & 2.94
  3.  *
  4.  * The Heater class represents a "blueprint" for a heater object
  5.  * in which you can adjust its temperature and adjust the
  6.  * increment in which you change the temperature.
  7.  *
  8.  * @author (Jonah Broyer)
  9.  * @version (1/18/2020)
  10.  */
  11. public class Heater
  12. {
  13.     // the temperature of the heater
  14.     private double temperature;
  15.     private double min;
  16.     private double max;
  17.     private double increment;
  18.  
  19.     /**
  20.      * Create a new heater
  21.      */
  22.     public Heater(double tempMinimum, double tempMaximum)
  23.     {
  24.         temperature = 15.0;
  25.         min = tempMinimum;
  26.         max = tempMaximum;
  27.         increment = 5.0;
  28.     }
  29.  
  30.     /**
  31.      * Increase the temperature of the heater.
  32.      */
  33.     public void warmer()
  34.     {
  35.         if(temperature <= max) {
  36.             temperature = temperature + increment;
  37.         }
  38.     }
  39.    
  40.     /**
  41.      * Decrease the temperature of the heater.
  42.      */
  43.     public void cooler()
  44.     {
  45.         if(temperature >= min) {
  46.             temperature = temperature - increment;
  47.         }
  48.     }
  49.    
  50.     /**
  51.      * Return what the heaters temperature is.
  52.      */
  53.     public double getTemperature()
  54.     {
  55.         return temperature;
  56.     }
  57.    
  58.     /**
  59.      * Set how much to increment the heater by.
  60.      */
  61.     public void setIncrement(double newIncrement)
  62.     {
  63.         if(newIncrement >= 0.0) {
  64.             increment = newIncrement;
  65.         }
  66.     }
  67. }
RAW Paste Data