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
- fives : int

+ ATM()
+ canWithdraw(amount : int) : boolean
+ withdraw(amount : int) : void
+ addTwenties(bills : int) : void
+ addFives(bills : int) : void
+ toString() : String

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
T - Add twenties to the ATM
F - Add fives to the ATM
Q - Quit

User enters:

t

Program displays:

How many twenties are you adding?

User enters:

5

Program displays:

ATM now has
5 twenty dollar bills, and 0 five dollar bills : $ 100

What would you like to do?

W - Withdraw money from the ATM
T - Add twenties to the ATM
F - Add fives to the ATM
Q - Quit

User enters:

F
Program displays:

How many fives are you adding?

User enters:

5
Program displays:

ATM now has
5 twenty dollar bills, and 5 five dollar bills : $ 125

What would you like to do?

W - Withdraw money from the ATM
T - Add twenties to the ATM
F - Add fives to the ATM
Q - Quit

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
4 twenty dollar bills, and 2 five dollar bills : $ 90
What would you like to do?

W - Withdraw money from the ATM
T - Add twenties to the ATM
F - Add fives to the ATM
Q - Quit

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
3 twenty dollar bills, and 2 five dollar bills : $ 70
What would you like to do?

W - Withdraw money from the ATM
T - Add twenties to the ATM
F - Add fives to the ATM
Q - Quit

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
3 twenty dollar bills, and 2 five dollar bills : $ 70
What would you like to do?

W - Withdraw money from the ATM
T - Add twenties to the ATM
F - Add fives to the ATM
Q - Quit

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
3 twenty dollar bills, and 2 five dollar bills : $ 70
What would you like to do?

W - Withdraw money from the ATM
T - Add twenties to the ATM
F - Add fives to the ATM
Q - Quit

User enters:

s
Program displays:

Not a valid command. Please reenter.
What would you like to do?

W - Withdraw money from the ATM
T - Add twenties to the ATM
F - Add fives to the ATM
Q - Quit

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
2 twenty dollar bills, and 2 five dollar bills : $ 50
What would you like to do?

W - Withdraw money from the ATM
T - Add twenties to the ATM
F - Add fives to the ATM
Q - Quit

User enters:

q

Program displays:

ATM now has
2 twenty dollar bills, and 2 five dollar bills : $ 50

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.