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

Account ac1 = new RegularAccount(500); System.out.println(ac1); ac1.applyInteres

ID: 3808096 • Letter: A

Question

Account ac1 = new RegularAccount(500);

System.out.println(ac1);

ac1.applyInterest();

System.out.println(ac1);

ac1.deposit(1200);

System.out.println(ac1);

ac1.applyInterest();

System.out.println(ac1);

ac1.withdraw(1000);

System.out.println(ac1);

ac1.applyInterest();

System.out.println(ac1);

PremiumAccount pacc1 = new PremiumAccount(500);

System.out.println(pacc1);

pacc1.applyInterest();

System.out.println(pacc1);

pacc1.deposit(1200);

System.out.println(pacc1);

pacc1.applyInterest();

System.out.println(pacc1);

--------------------------------------------

The code should output the following:

Regular Account: The balance is $500.00

Regular Account: The balance is $500.00

Regular Account: The balance is $1700.00

Regular Account: The balance is $1707.00

Regular Account: The balance is $707.00

Regular Account: The balance is $707.00

Premium Account: The balance is $500.00

Premium Account: The balance is $507.50

Premium Account: The balance is $1707.50

Premium Account: The balance is $1733.11

(Use material from Ch. 13) A bank offers two types of accounts to it customer: RegularAccount and PremiumAccount. s All accounts have a balance and methods: deposit and withdraw which both accept an amount of money and either adds to the balance (deposit) or subtracts the amount from the balance (withdraw). An account also has a toString. method that returns a string like this: The balance is $3,603.35. Accounts also have a n apply Interest method that calculates the interest and then adds this to the balance. Howeve interest is calculated differently for the two types of accounts. A RegularAccount earns 1% interest for the balance over $1000. The PremiumAccount earns 1.5% interest on the entire balance Do the following: a. Model this situation with a class dia ram. You will add to this diagram for Problem 3. Notice: Design "Account" as an abstract class. Define its balance as a protected data field rather than private b. Write the required classes. c. Write a tester, Accou Tester java and use the following main to test: +l

Explanation / Answer

Hi Please find my implementation.

Please let me know in case of any issue.

public abstract class Account{

   protected double balance;

   public void withdraw(double amount){

       if(balance-amount < 0){

           System.out.println("Balance is low");

       }else

           balance = balance - amount;

   }

   public void deposit(double amount){

       balance = balance + amount;

   }

   public abstract void applyInterest();

   @Override

   public String toString() {

       return "The balance is $"+String.format("%.2f", balance);

   }

}

class PremiumAccount extends Account{

   public PremiumAccount(double amount) {

       balance = amount;

   }

  

   @Override

   public void applyInterest() {

       balance = balance + balance*0.015;

   }

}

class RegularAccount extends Account{

  

   public RegularAccount(double amount) {

       balance = amount;

   }

   @Override

   public void applyInterest() {

       if(balance > 1000)

           balance = balance + (balance - 1000)*0.01;

   }

}

public class AccountTester {

   public static void main(String[] args) {

       Account ac1 = new RegularAccount(500);

       System.out.println(ac1);

       ac1.applyInterest();

       System.out.println(ac1);

       ac1.deposit(1200);

       System.out.println(ac1);

       ac1.applyInterest();

       System.out.println(ac1);

       ac1.withdraw(1000);

       System.out.println(ac1);

       ac1.applyInterest();

       System.out.println(ac1);

       PremiumAccount pacc1 = new PremiumAccount(500);

       System.out.println(pacc1);

       pacc1.applyInterest();

       System.out.println(pacc1);

       pacc1.deposit(1200);

       System.out.println(pacc1);

       pacc1.applyInterest();

       System.out.println(pacc1);

   }

}

/*

Sample run:

The balance is $500.00

The balance is $500.00

The balance is $1700.00

The balance is $1707.00

The balance is $707.00

The balance is $707.00

The balance is $500.00

The balance is $507.50

The balance is $1707.50

The balance is $1733.11

*/

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