Added coffee maker and reordered exercises

This commit is contained in:
Thomas Harvey
2015-11-23 23:25:30 -05:00
parent 785c9cb5d1
commit 4ee8623af8
17 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,12 @@
## Coffee Maker
You will be designing a software implementation of a simple coffee maker. The following hardware needs to be monitored. Write the methods for:
* The heating element for the boiler. It can be turned on or off.
* The heating element for the warmer plate. It can be turned on or off.
* The sensor for the warmer plate. It has three states: warmerEmpty, potEmpty, potNotEmpty.
* A sensor for the boiler, which determines whether there is water present. It has two states: boilerEmpty or boilerNotEmpty.
* The Brew button. This is a momentary button that starts the brewing cycle. It has an indicator that lights up when the brewing cycle is over and the coffee is ready.
* A pressure-relief valve that opens to reduce the pressure in the boiler. The drop in pressure stops the flow of water to the filter. It can be opened or closed.
You should do this OO. Think about the flow of information and the flow of state. Your methods should not have to worry about each other's implementations, just their interface. Take your time to make sure everything is interacting with each other as they should. This is an exercise in design, not code. If you design well, the coding will be easy.

View File

@ -0,0 +1,108 @@
# containment vessel
class Pot:
def __init__(self):
self.has_pot = True
self.has_coffee = False
self.warming_plate_on = False
self.is_brewing = False
def is_ready(self):
return self.has_pot
def start(self):
self.is_brewing = True
def pause(self):
if self.
self.warming_plate_on = False
def resume(self):
if self.has_coffee:
self.warming_plate_on = True
def done(self):
self.is_brewing = False
# hot water source
class WaterSource:
def __init__(self):
# default to false later
self.has_water = True
self.boiler_on = False
self.valve_open = True
def is_ready(self):
# "NotEmpty" = True
return self.has_water
def boiling(self):
return self.boiler_on
def start(self):
self.boiler_on = True
self.valve_open = False
def pause(self):
self.valve_open = True
self.boiler_on = False
def resume(self):
self.valve_open = False
self.boiler_on = True
def done(self):
self.boiler_on = False
self.valve_open = True
class CoffeeMaker:
def __init__(self):
self.pot = Pot()
self.water_source = WaterSource()
self.brew_light = False
def push_brew_button(self):
self.brew()
def remove_pot(self):
self.pot.has_pot = False
def add_water(self):
self.water_source.has_water = True
def poll(self):
# is pot on warmer plate
if self.pot.is_ready():
if self.water_source.boiling():
self.pot.has_coffee = True
self.water_source.valve_open = False
# does pot have coffee
if self.pot.has_coffee:
self.pot.warming_plate_on = True
else:
self.pot.warming_plate_on = False
#
if not self.water_source.has_water:
self.water_source.done()
self.brew_light = True
if not self.water_source.has_water and not self.pot.has_coffee and self.pot.is_brewing:
self.pot.done()
self.brew_light = False
else:
self.water_source.valve_open = True
self.pot.has_coffee = False
def brew(self):
if not self.pot.is_ready() or not self.water_source.is_ready():
return False
self.pot.start()
while self.water_source.boiling():
self.poll()
while self.pot.has_coffee():
self.poll()