Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Purpose inheritance. Purpose is to practice using regular The Account superclass

ID: 3835059 • Letter: P

Question

Purpose inheritance. Purpose is to practice using regular The Account superclass a simple bank account. First design, code and test a class called Account that implements a This will be your superclass. Use exactly and only these instance variables: -an identifying account number e.g. "123" private String ID -balance of the account in dollars e.g. si.23 private double balance private int deposits -number of withdrawals made this month private int withdrawals -maintain the total monthly service charges incurred private double service here, in dollars Account will have the following methods. Be careful to implement the steps of each method in exactly the order given below: constructor -has parameters for the ID and starting balance (in dollars) -must initialize all instance variables appropriate get and set methods -you have to decide during design what get and set methods are required in your program -has a parameter for the deposit amount in dollars -add the deposit amount to the balance -add l to the number of deposits -add a deposit fee of $1.00 to the monthly service charge -note that the deposit fee is NOT deducted from balance at the time of the deposit transaction you are required to use static final constants for all of the 'magic number fee amounts) -has a parameter for the withdrawal amount in dollars -subtract the withdrawal amount from the balance

Explanation / Answer

/**
*
* @author Sam
*/
public class Accounts {
    private String ID;
    private double balance;
    private int deposits;
    private int withdrawls;
    private double service;

    public Accounts(String ID, double balance) {
        this.ID = ID;
        this.balance = balance;
        service = deposits = withdrawls = 0;
    }

    public String getID() {
        return ID;
    }

    public void setID(String ID) {
        this.ID = ID;
    }

    public double getService() {
        return service;
    }

    public void setService(double service) {
        this.service = service;
    }

    public double getBalance() {
        return balance;
    }

    public int getDeposits() {
        return deposits;
    }

    public int getWithdrawls() {
        return withdrawls;
    }
   
    void dep(double amount) {
        balance += amount;
        deposits++;
        service += 1;
    }
   
    void wd(double amount) {
        balance -= amount;
        withdrawls ++;
        if (withdrawls > 2)
            service += 3;
        else
            service += 2;
    }

    @Override
    public String toString() {
        return "Accounts[" + "ID=" + ID + ", balance=" + balance + ", deposits=" + deposits + ", withdrawls=" + withdrawls + ", service=" + service + ']';
    }
   
}

class Savings extends Accounts {
    boolean active;

    public Savings(String ID, double balance) {
        super(ID, balance);
        updateActive();
    }
   
    private void updateActive() { //this method checks if an account is active
        active = getBalance() > 250;
    }

    @Override
    void wd(double amount) {
        if (active) {
            super.wd(amount);
            updateActive();
        }
        else
            System.err.println("Saving ID: " + getID() + ": Withdrawl not allowed.");
    }

    @Override
    void dep(double amount) {
        super.dep(amount);
        updateActive();
    }

    @Override
    public String toString() {
        return "Savings[" + "ID=" + getID() + ", balance=" + getBalance() + ", deposits=" + getDeposits() + ", withdrawls=" + getWithdrawls() + ", service=" + getService() + "][active=" + active + ']';
    }
   
}

The code is kept as simple as possible. I havnt commented the code because every method description is given in the question. I hope this helps you. Let me know if youneed any help.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote