Learn how to use Wrapper classes in practical applications, such as managing financial transactions in a bank account
Subsection8.4.1Overview
The following program simulates a bank account and allows users to deposit, withdraw, and track the transaction history of their account.
deposit(amount)
Adds money to the account
withdrawal(amount)
Takes money out of the account
displayTransactions()
Prints deposits and withdrawals as they were recorded in the transactions ArrayList.
displayBalance()
Prints the balance of the account
Subsection8.4.2Instructions
Complete the following methods:
deposit(amount)
Ensures that only valid deposits (positive numbers) are added to the account. Record the transaction as a positive value in the transactions ArrayList.
Prints a message including the depositor’s name, the deposited amount, and the new balance.
Error messages are printed for unsuccessful deposits.
withdrawal(amount)
Ensures that withdrawals are within the available balance. Valid withdrawals are recorded as a negative value in the transactions ArrayList.
If the conditions are not met, print an error message indicating the withdrawal was unsuccessful.
displayTransactions()
Prints all the transactions (deposits and withdrawals) recorded.
displayBalance()
Prints the current balance of the account.
The expected output is:
[John Doe] Current balance: 100.0
[John Doe] Deposited $0.25. (New Balance: 100.25)
[ERROR, John Doe] Unsuccessful withdrawal of 100.5.
[John Doe] Withdrew $40.9. (New Balance: 59.35)
[ERROR, John Doe] Unsuccessful deposit of -90.55. Minimum deposit amount is $0.01.
[John Doe] Deposited $3000.0. (New Balance: 3059.35)
[John Doe] Transaction History: 0.25, -40.9, 3000.0,
[John Doe] Current balance: 3059.35