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

Create an abstract class named Account for a bank. Include an integer field for

ID: 3777338 • Letter: C

Question

Create an abstract class named Account for a bank. Include an integer field for the account number and a double field for the account balance. Also include a constructor that requires an account number and that sets the balance to 0.0. Include a set method for the balance. Also include two abstract get methods—one for each field. Create two child classes of Account: Checking and Savings. Within the Checking class, the get method displays the String “Checking Account Information”, the account number, and the balance. Within the Savings class, add a field to hold the interest rate, and require the Savings constructor to accept an argument for the value of the interest rate. The Savings get method displays the String “Savings Account Information”, the account number, the balance, and the interest rate. Write an application that demonstrates you can instantiate and display both Checking and Savings objects. Save the files as Account.java, Checking.java, Savings.java, and DemoAccounts.java.

Explanation / Answer

DemoAccounts.java


public class DemoAccounts {
   public static void main(String arg[]){
       Account acc1 = new Checking(1001);
       acc1.setAccountBalance(1000);
       Account acc2 = new Savings(2001, 8.5);
       acc2.setAccountBalance(2000);
       System.out.println(acc1.getAccountDetails());
       System.out.println(acc2.getAccountDetails());
   }
}

Account.java


public abstract class Account {
   private int accountNo;
   private double accountBalance;
   public Account(int accNo){
       this.accountNo = accNo;
       accountBalance = 0.0;
   }
   public int getAccountNo() {
       return accountNo;
   }
   public double getAccountBalance() {
       return accountBalance;
   }
   public void setAccountBalance(double accountBalance) {
       this.accountBalance = accountBalance;
   }
   public abstract String getAccountDetails();
  
}

Checking.java


public class Checking extends Account{
   public Checking(int accNO){
       super(accNO);
   }
   public String getAccountDetails(){
       return "Checkings Account Information Account No: "+getAccountNo()+" Account Balance: "+getAccountBalance();
   }
}

Savings.java


public class Savings extends Account{
   private double interestRate;
   public Savings(int accNo, double rate){
       super(accNo);
       this.interestRate = rate;
   }
   public double getInterestRate() {
       return interestRate;
   }
   public void setInterestRate(double interestRate) {
       this.interestRate = interestRate;
   }
   public String getAccountDetails(){
       return "Savings Account Information Account No: "+getAccountNo()+" Account Balance: "+getAccountBalance()+" Interest Rate: "+getInterestRate();
   }
}

Output:

Checkings Account Information
Account No: 1001
Account Balance: 1000.0
Savings Account Information
Account No: 2001
Account Balance: 2000.0
Interest Rate: 8.5

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