Write a program for a bank that lets them create objects representing customer savings accounts and checking accounts. Your program should have the following three classes: Account , with the...

1 answer below »

Write a program for a bank that lets them create objects representing customer savings accounts and checking accounts. Your program should have the following three classes:




  • Account, with the following data:


    • A field named 'balance' which contains how much is in the account.

    • A constructor which allows the client to initialize 'balance'

    • Override toString to print how much is currently in the account.

    • A 'deposit' method which adds money to 'balance' and a'withdraw' method which removes money from 'balance'.

    • An ArrayList named 'transactions' that holds strings. Give it 'protected' access. When a transaction (withdrawal or deposit) occurs, add a string to 'transactions' describing the transaction. i.e.: "$100 withdrawn from the account"

    • A 'displayTransactions' method which prints out each string in 'transactions'.




  • SavingsAccount, which extends Account, with the following data.

    • A 'calculateInterest' method which increases the 'balance' by 2%. It also adds a string to the inherited 'transactions' ArrayList. i.e. "$30 in interest added to the account".

    • Override 'withdraw':

      • If the amount the client wants to withdraw would bring 'balance' below $200, charge a $10 fee and do not perform the withdrawal.

      • Otherwise, pass the withdrawal amount to the superclass version of the 'withdraw'.






  • CheckingAccount, which extends Account, with the following data.

    • A 'numBounced' field to track how many checks have bounced. This field should have a getter.

    • A 'processCheck' method to simulate a customer's check being cashed, with two parameters: an amount and who the check was written to.

      • If the check would bring 'balance' below 0, increment 'numBounced' and charge a $25 fee (note: The fee might bring balance below 0, which is okay).

      • Otherwise, subtract the amount from 'balance' and add a string to the inherited 'transactions' ArrayList. i.e. "$50 check cashed by Target".







  • On Main.java, in the main method, create a CheckingAccount and SavingsAccount object. Test the methods you wrote!Note: You do not need user input, you can simply hard-code the values.

Answered Same DayMay 20, 2021

Answer To: Write a program for a bank that lets them create objects representing customer savings accounts and...

Kshitij answered on May 20 2021
136 Votes
Account.java
Account.java
/*   Created by IntelliJ IDEA.
 *   Author: Kshitij Varshney (kshitijvarshne
1)
 *   Date: 21-May-21
 *   Time: 12:25 AM
 *   File: Account.java
 */
package May.may21_21;
import java.util.ArrayList;
public class Account {
    public int balance;
    public ArrayList transactions;
    public Account(int balance) {
        this.balance = balance;
        transactions = new ArrayList<>();
    }
    public void deposit(int balance) {
        this.balance += balance;
        transactions.add("$" + balance + " " + "deposit");
    }
    public void withdraw(int balance) {
        if (this.balance > balance) {
            this.balance -= balance;
            transactions.add("$" + balance + " " + "withdrawn");
        } else {
            System.out.println("balance is low");
        }
    }
    @Override
    public String toString() {
        return "Account{" +
                "balance=" + balance +
                '}';
    }
    public void displayTransactions() {
    ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here