Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # classes
- class House
- def initialize(temp, ac_on, furnace_on)
- # instance variables
- @temp = temp
- @ac_on = ac_on
- @furnace_on = furnace_on
- end
- def update_temperature!(ac_on, furnace_on)
- if (ac_on == true and furnace_on == false)
- @temp -= 2
- puts self.display
- elsif (ac_on == false and furnace_on == true)
- @temp += 1
- puts self.display
- elsif (furnace_on == true and ac_on == true)
- puts "Why do you have the AC and furnace on at the same time?"
- puts self.display
- end
- end
- def ask_ac
- puts "Turn AC on?"
- answer = gets.chomp
- if answer == "yes"
- @ac_on = true
- @furnace_on = false
- puts "Turning the AC on."
- self.update_temperature!(ac_on, furnace_on)
- else
- puts "Leaving AC off."
- end
- puts "The current temperature is #{@temp}."
- end
- def ask_furnace
- puts "Turn furnace on?"
- answer = gets.chomp
- if answer == "yes"
- @ac_on = false
- @furnace_on = true
- puts "Turning the furnace on."
- self.update_temperature!(ac_on, furnace_on)
- else
- puts "Leaving furnace off."
- end
- puts "The current temperature is #{@temp}."
- end
- def ac_switch(ac_yes)
- @ac_on = true
- puts "Turning the AC on."
- end
- def display
- puts "The current temperature is #{@temp}."
- end
- end
- house1 = House.new(75, false, false)
- house1.update_temperature!(false, false)
- house1.ask_ac
- house1.ask_furnace
- house2 = House.new(55, false, false)
- house2.ask_ac
- house2.ask_furnace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement