Question: Do not use any data structures such as array or ArrayList to store data. An ATM card issued by a bank enables the customer to
Do not use any data structures such as array or ArrayList to store data.
An ATM card issued by a bank enables the customer to access his/her bank account via an automated teller machine (ATM) to perform transactions such as deposit, cash withdrawal, and checking balance. Use object oriented programming approach, write a program to simulate the ATM service.
(ATMCard.java)Write the class definition ATMCard based on the following class diagram:
| ATMCard |
| - accountNumber : int - firstName : String - lastName : String - balance : double |
|
+ ATMCard() + ATMCard(int, String, String, double)
+ setAccountNumber(int) : void + getAccountNumber() : int
+ setFirstName(String) : void + getFirstName() : String
+ setLastName(String) : void + getLastName() : String
+ setBalance( double ): void + getBalance() : double;
+ deposit(double): void + withdraw(double): void
+ toString(): String |
Private instance variables: accountNumber, firstName, lastName, and balance.
Two constructors. Ensure that the balance containing a valid value (>=0).
Public setters and getters for private instance data members.
Two public instance methods:
Method deposit should add deposited money to the current balance.
It adds a deposit amount to the current balance.
Ensure that a negative value is not added to the current balance.
Method withdraw should withdraw money from the Account.
It subtracts a withdraw amount from the current balance.
Ensure that the withdrawal amount does not exceed the current balance.
Ensure that a negative value is not withdrawn.
toString method.
(ATMMachine.java) Write a menu-driven client program that uses the ATMCard class to simulate the banking transactions.
Incorporate this reference in the ATMCard class.
Sample run:
| ***************Open Bank Account and Issue ATM Card****************** Enter first name: Jon Enter last name: Doe Enter opening deposit: $500 Your new account has been created and your new ATM card has been issued! Account Number: 9001 Name: Jon Doe Account Balance: $500.00 Welcome to "ATM Machine" ***************************************** 1 --- Deposit 2 --- Withdraw 3 --- Check balance 0 --- Exit ***************************************** Select an option: 1 Amount to deposit: $-200 Cannot deposit negative cash, try again. ***************************************** 1 --- Deposit 2 --- Withdraw 3 --- Check balance 0 --- Exit ***************************************** Select an option: 1 Amount to deposit: $200 New account balance: $700.00 ***************************************** 1 --- Deposit 2 --- Withdraw 3 --- Check balance 0 --- Exit ***************************************** Select an option: 2 Amount to withdraw: $800 No enough cash to withdraw, try again. ***************************************** 1 --- Deposit 2 --- Withdraw 3 --- Check balance 0 --- Exit ***************************************** Select an option: 2 Amount to withdraw: $80 New account balance: $620.00 ***************************************** 1 --- Deposit 2 --- Withdraw 3 --- Check balance 0 --- Exit ***************************************** Select an option: 3 Account Number: 9001 Name: Jon Doe Account Balance: $620.00
***************************************** 1 --- Deposit 2 --- Withdraw 3 --- Check balance 0 --- Exit ***************************************** Select an option: 6 Invalid selection (enter 1, 2, 3, or 0), please try again. ***************************************** 1 --- Deposit 2 --- Withdraw 3 --- Check balance 0 --- Exit ***************************************** Select an option: 0 Thank you for banking with us! |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
