A Soda Machine
What is a soda machine
- Takes coins or bills, in USD
+ 5, 10, 25 coins
+ $1, $5, $10 bills
- Insert coin or bill
+ if the bill or coin is of the correct type and currency
then accept coin or bill
else reject coin or bill
- Push a soda button
+ If not items of that type
- Display out of order
+ If insufficient currency and there are items to sell
- display the price of the item tied to the button
+ Otherwise
- Dispense soda
- If we need to make change, make change.
- Push a coin return button
+ return amount of coins or bills inserted.
What data structures (or storage things) will we need?
How are we going to model coins/bills in the system
Some array of coins,
Some array of bills
We will need to keep track of the total deposited (probably float)
Cans
Probably an 2d array of cans
- one dimension is the button
- one dimension is the can
A 1d array of prices for each bin.
-------
An owner
- check inventory
- check cash
- add soda
- replace money
- remove money
- location relative to traffic
-------
An architect/building owner
- location: relative to resources (electric, drain)
- dimensions
- weight
- power consumption
- noise and light pollution
Interaction for our program might look like this:
Deposit $1
Display $1 USD deposited
Deposit 25c USD
Display $1.25 deposited
Deposit 25c CAN
Reject coin
Display $1.25 deposited
Deposit 25c USD
Display $1.50 deposited
Push Can Button 1
Dispense Can from Bin 1
A Functional Decomposition
MAIN
while not done
GetCommand (command)
done = ProcessCommand ( command
GetCommand -> return command
Read a command from the input
Process a command
Parse the command
if deposit
DoDeposit
else if buttonPush
DoButtonPush
else
Do Error
DoADeposit (amount)
Validate deposit
if valid deposit
Deposited += amount
else
reject deposit
// What data structures do we need down here?