Advertisement
Guest User

Untitled

a guest
Mar 24th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. # classes
  2.  
  3. class House
  4.  
  5. def initialize(temp, ac_on, furnace_on)
  6. # instance variables
  7. @temp = temp
  8. @ac_on = ac_on
  9. @furnace_on = furnace_on
  10.  
  11. end
  12.  
  13. def update_temperature!(ac_on, furnace_on)
  14.  
  15. if (ac_on == true and furnace_on == false)
  16. @temp -= 2
  17. puts self.display
  18. elsif (ac_on == false and furnace_on == true)
  19. @temp += 1
  20. puts self.display
  21. elsif (furnace_on == true and ac_on == true)
  22. puts "Why do you have the AC and furnace on at the same time?"
  23. puts self.display
  24. end
  25.  
  26. end
  27.  
  28. def ask_ac
  29. puts "Turn AC on?"
  30. answer = gets.chomp
  31. if answer == "yes"
  32. @ac_on = true
  33. @furnace_on = false
  34. puts "Turning the AC on."
  35. self.update_temperature!(ac_on, furnace_on)
  36. else
  37. puts "Leaving AC off."
  38. end
  39. puts "The current temperature is #{@temp}."
  40. end
  41.  
  42. def ask_furnace
  43. puts "Turn furnace on?"
  44. answer = gets.chomp
  45. if answer == "yes"
  46. @ac_on = false
  47. @furnace_on = true
  48. puts "Turning the furnace on."
  49. self.update_temperature!(ac_on, furnace_on)
  50. else
  51. puts "Leaving furnace off."
  52. end
  53. puts "The current temperature is #{@temp}."
  54. end
  55.  
  56. def ac_switch(ac_yes)
  57. @ac_on = true
  58. puts "Turning the AC on."
  59. end
  60.  
  61. def display
  62. puts "The current temperature is #{@temp}."
  63. end
  64.  
  65. end
  66.  
  67. house1 = House.new(75, false, false)
  68.  
  69. house1.update_temperature!(false, false)
  70.  
  71. house1.ask_ac
  72. house1.ask_furnace
  73.  
  74. house2 = House.new(55, false, false)
  75.  
  76. house2.ask_ac
  77. house2.ask_furnace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement