ITEC 120 | Back to Assignment index page |
Assignment 4
- ATM Due Friday, Nov 19, 4pm. Submit your program to the RU09 folder in your directory on neelix. |
Description: You'll write a class to represent an ATM machine, and a driver to test it.
The ATM class:
This class represents an ATM which can contain five dollar bills and twenty
dollar bills.
ATM
|
- twenties : int |
+ ATM() |
The instance data:
The methods:
The driver:
The driver will give the user 4 choices:
W
- Withdraw money from the ATM
T - Add twenties to the ATM
F - Add fives to the ATM
Q - Quit
The driver should be case-insensitive - that is, 'w' or 'W' should be recognized as a withdraw funds command. If the user enters a character other than 'w', 't', 'f'', or 'q', they should be told they entered an invalid command and be given the 4 choices again.
The driver will do all the validation. (So, in the ATM class file, you can assume the parameters to your methods are valid).
Withdraw - if the user chooses to withdraw, prompt them for the amount they would like to withdraw. The withdrawal amount must be a positive multiple of 5. If the withdrawal can be made, withdraw the amount. Otherwise, just give the user a message that says the atm cannot make the withdrawal, and show the contents of the ATM.
Add twenties - if the user chooses to add twenties, prompt them for the number of twenty dollar bills they would like to add. The number of bills must be positive. Add the twenties to the ATM, and show the contents of the ATM.
Add twenties - if the user chooses to add fives, prompt them for the number of five dollar bills they would like to add. The number of bills must be positive. Add the fives to the ATM, and show the contents of the ATM.
Quit - quits, and show the contents of the ATM..
Study the following run carefully.
Program displays: |
What would you like to do? W - Withdraw money
from the ATM |
User enters: |
t |
Program displays: |
How many twenties are you adding? |
User enters: |
5 |
Program displays: |
ATM now has W - Withdraw money
from the ATM |
User enters: |
F |
Program displays: |
How many fives are you adding? |
User enters: |
5 |
Program displays: |
ATM now has W - Withdraw money
from the ATM |
User enters: |
w |
Program displays: | How much money to you want? Please enter a multiple of 5: |
User enters: |
35 |
Program displays: |
$35 withdrawn. ATM now
has W - Withdraw money
from the ATM |
User enters: |
w |
Program displays: | How much money to you want? Please enter a multiple of 5: |
User enters: |
33 |
Program displays: | Must enter a positive multiple of 5: |
User enters: |
20 |
Program displays: |
$20 withdrawn. ATM now
has W - Withdraw money
from the ATM |
User enters: |
W |
Program displays: | How much money to you want? Please enter a multiple of 5: |
User enters: |
150 |
Program displays: |
Sorry, withdrawal cannot
be made. ATM now has W - Withdraw money
from the ATM |
User enters: |
w |
Program displays: | How much money to you want? Please enter a multiple of 5: |
User enters: |
35 |
Program displays: |
Sorry, withdrawal cannot
be made. ATM now has W - Withdraw money
from the ATM |
User enters: |
s |
Program displays: |
Not a valid command.
Please reenter. W - Withdraw money
from the ATM |
User enters: |
w |
Program displays: | How much money to you want? Please enter a multiple of 5: |
User enters: |
20 |
Program displays: |
$20 withdrawn. ATM now
has W - Withdraw money
from the ATM |
User enters: |
q |
Program displays: |
ATM now has |
NOTES : Notice that there are a number of ways a withdrawal cannot be made. If there is not enough money in the ATM, the withdrawal cannot be made, obviously. But, it's possible to have enough money in the atm and still not be able to make the withdrawal. For example, suppose there are 2 twenty dollar bills in the ATM (40 dollars) and the user wishes to withdraw $15. Can't be done because there are no 5 dollar bills!
Advice: Use incremental design. Write a class with everything except the canWithdraw and withdraw methods. Write a driver which does everything but withdraw. Get it to run. Then add the withdrawal methods.
TURNING IN YOUR PROGRAM: You will turn in two files. You'll have the driver program and your ATM file. Submit both files to neelix in the appropriate folder.