Description
Now, let's simulate an actual coffee machine! This coffee machine will have a limited supply of water, milk, coffee beans, and disposable cups. Additionally, it will track how much money it earns from selling coffee.
The coffee machine will have three main functions:
- It can sell different types of coffee: espresso, latte, and cappuccino. Of course, each variety would require a different amount of supplies, however, in any case, would need only one disposable cup for a drink.
- A special worker should be able to replenish the machine's supplies.
- Another special worker should be able to collect the money earned by the machine.
Objectives
Write a program that offers three actions: buying coffee, refilling supplies, or taking its money out. Note that the program is supposed to perform only one of the mentioned actions at a time for each input. It should update the coffee machine's state accordingly i.e. calculate the amounts of remaining ingredients and the total money collected; and display them before and after each action.
- First, your program reads one option from the standard input, which can be
"buy","fill","take". If a user wants to buy some coffee, the input is"buy". If a special worker thinks that it is time to fill out all the supplies for the coffee machine, the input line will be"fill". If another special worker decides that it is time to take out the money from the coffee machine, you'll get the input"take". - If the user writes
"buy"then they must choose one of three types of coffee that the coffee machine can make: espresso, latte, or cappuccino.- For a cup of espresso, the coffee machine needs 250 ml of water and 16 g of coffee beans. It costs $4.
- For a latte, the coffee machine needs 350 ml of water, 75 ml of milk, and 20 g of coffee beans. It costs $7.
- And for a cappuccino, the coffee machine needs 200 ml of water, 100 ml of milk, and 12 g of coffee beans. It costs $6.
- If the user writes
"fill", the program should ask them how much water, milk, coffee beans, and how many disposable cups they want to add into the coffee machine. - If the user writes
"take"the program should give all the money that it earned from selling coffee.
In summary, your program should display the coffee machine's current state, process one user action, and then display the updated state. Aim to implement each action using separate functions.
Note:
- When the user writes
"buy", they will be prompted to choose a coffee type by entering a number: 1 for espresso, 2 for latte, 3 for cappuccino. - Initially, the coffee machine has $550, 400 ml of water, 540 ml of milk, 120 g of coffee beans, and 9 disposable cups.
Examples
The greater-than symbol followed by a space (> ) represents the user input. Note that it's not part of the input.
Example 1:
The coffee machine has:
400 ml of water
540 ml of milk
120 g of coffee beans
9 disposable cups
$550 of money
Write action (buy, fill, take):
> buy
What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino:
> 3
The coffee machine has:
200 ml of water
440 ml of milk
108 g of coffee beans
8 disposable cups
$556 of money
Example 2:
The coffee machine has:
400 ml of water
540 ml of milk
120 g of coffee beans
9 disposable cups
$550 of money
Write action (buy, fill, take):
> fill
Write how many ml of water you want to add:
> 2000
Write how many ml of milk you want to add:
> 500
Write how many grams of coffee beans you want to add:
> 100
Write how many disposable cups you want to add:
> 10
The coffee machine has:
2400 ml of water
1040 ml of milk
220 g of coffee beans
19 disposable cups
$550 of money
Example 3:
The coffee machine has:
400 ml of water
540 ml of milk
120 g of coffee beans
9 disposable cups
$550 of money
Write action (buy, fill, take):
> take
I gave you $550
The coffee machine has:
400 ml of water
540 ml of milk
120 g of coffee beans
9 disposable cups
$0 of money