Skip to main content

Section 6.4 Stretch Level

Subsection 6.4.1 Overview

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

Subsection 6.4.2 Instructions

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
You have attempted of activities on this page.