CSCI 235 Project #5 Writing your own class

$30.00

Category:

Description

5/5 - (2 votes)

Documentation and style will be assessed as part of your grade. Follow the full code guidelines.
This project doesn’t provide any starting file, but all necessary components for this assignment have been
introduced in the previous code examples, lab assignments, or projects.
Write a class that simulates ATM withdraw transactions and a driver to test the class.
The ATM class should meet the following conditions:
• It works for withdrawal transactions.
o It takes and dispenses twenty dollar bills and five dollar bills.
• The ATM should be initially empty (No dollar bill).
• The method toString() should return the number of twenties, number of fives, and the amount of
money in the AMT in a formatted String.
• The class should provide necessary methods to add twenties and fives to the AMT.
• The class should provide necessary methods to withdraw money from the ATM.
You need to identify necessary instance variables and methods of the ATM class (ATM.java) by considering its
functionality and the user, i.e., a driver.
The driver program (ATMdriver.java) will provide the following four options:
• W: withdraw money from the ATM
• T: add twenties to the ATM
• F: add fives to the ATM
• Q: quit
If the user provides an invalid input for the option, it should present an error message and present the four menu
options again until a valid option is selected.
An input for the options should be case-insensitive, i.e., w or W should be recognized as a withdraw money
command.
Withdraw
If this option is selected, the driver should prompt the user for an amount. The amount must be positive and a
multiple of 5. Validate the amount, and if the withdrawal can be made, withdraw the amount, and present a
confirmation message. Otherwise, present a message indicating that the transaction is not possible. At the end of
the transaction, show the contents of the ATM by calling toString() method.
• Think about various cases that withdrawals cannot be made for a given ATM condition.
• Where should you put a method to see if a withdrawal can be made or not?
Add twenties
If this option is selected, prompt for the number of twenty dollar bills that the user wants to add. The number of
bills must be positive. If the input is valid, add the amount and show the contents of the ATM.
Add fives
If this option is selected, prompt for the number of five dollar bills that the user wants to add. The number of bills
must be positive. If the input is valid, add the amount and show the contents of the ATM.
2
Quit
Show the contents of the ATM, and quit the program.
An example run of the driver:
Please select an option:
W: withdraw money from the ATM
T: add twenties to the ATM
F: add fives to the ATM
Q: quit
User input: t
How many twenties do you want to add?
User input: 10
ATM now has
10 twenty dollar bills and 0 five dollar bills: $200
Please select an option:
W: withdraw money from the ATM
T: add twenties to the ATM
F: add fives to the ATM
Q: quit
User input: W
How much do you want to withdraw? Please enter a multiple of 5.
User input: 40
$40 withdrawn.
ATM now has
8 twenty dollar bills and 0 five dollar bills: $160
Please select an option:
W: withdraw money from the ATM
T: add twenties to the ATM
F: add fives to the ATM
Q: quit
User input: W
How much do you want to withdraw? Please enter a multiple of 5.
User input: 15
Sorry, the transaction cannot be made.
ATM now has
8 twenty dollar bills and 0 five dollar bills: $160
Please select an option:
W: withdraw money from the ATM
T: add twenties to the ATM
F: add fives to the ATM
Q: quit
What to submit:
• The two Java files (ATM.java and ATMdriver.java) to Schoology.