123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
-
- /**
- * Write a description of class Heater here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class Heater
- {
- // instance variables - replace the example below with your own
- private int temperature;
- private int min;
- private int max;
- private int increment;
-
- /**
- * Constructor for objects of class Heater
- */
- public Heater(int minTemp, int maxTemp)
- {
- // initialise instance variables
- temperature = 15;
- min = minTemp;
- max = maxTemp;
- increment = 5;
- }
-
- /**
- * increase temperature by increment
- */
- public void warmer()
- {
- // put your code here
- if(temperature + increment <= max){
- temperature += increment;
- } else {
- System.out.print("cannot set temperature above max");
- }
- }
-
- /**
- * decrease temperature by increment
- */
- public void cooler()
- {
- // put your code here
- if(temperature - increment >= min){
- temperature -= increment;
- } else {
- System.out.print("cannot set temperature below min");
- }
- }
-
- /**
- * return temperature
- */
- public int getTemperature()
- {
- // put your code here
- return temperature;
- }
-
- /**
- * increase temperature by increment
- */
- public void setIncrement(int newIncrement)
- {
- // put your code here
- increment = newIncrement;
- }
- }
|