Advertisement
rmword

Untitled

Sep 28th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. /**
  2. *
  3. * @author Rifqi Mukti W
  4. * @version 29/09/2017
  5. */
  6. public class Heater
  7. {
  8. // instance variables - replace the example below with your own
  9. private double temperature;
  10. private double min;
  11. private double max;
  12. private double increment;
  13. /**
  14. * Constructor for objects of class Heater
  15. */
  16. public Heater(double temperatureMin, double temperatureMax)
  17. {
  18. temperature = 15.0;
  19. min = temperatureMin;
  20. max = temperatureMax;
  21. increment = 5.0;
  22. }
  23.  
  24. public void warmer()
  25. {
  26. if (temperature + increment > max)
  27. {
  28. System.out.println("The value is invalid.");
  29. }
  30. else
  31. {
  32. temperature = temperature + 5.0;
  33. }
  34. }
  35.  
  36. public void cooler()
  37. {
  38. if (temperature + increment < min)
  39. {
  40. System.out.println("The value is invalid.");
  41. }
  42. else
  43. {
  44. temperature = temperature - 5.0;
  45. }
  46. }
  47.  
  48. public void setIncrement(double input)
  49. {
  50. if (input < 0)
  51. System.out.println("Wrong input!.");
  52. else increment = input;
  53. }
  54.  
  55. public double getTemperature()
  56. {
  57. return temperature;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement