Write an application named AccountArray in which you enter d

Write an application named AccountArray in which you enter data for a mix of 10 Checking and Savings accounts. Use a for loop to display the data. Save the file as AccountArray.java.

Solution

Account.java

public abstract class Account {
   protected int account_number;
   protected double balance;
   public Account(int account_number) {
       super();
       this.account_number = account_number;
       this.balance = 0.0;
   }

   public abstract int getAccountNumber();
   public abstract double getBalance();
   public abstract void getAccInfo();
  
   public void setBalance(double bal)
   {
       this.balance=bal;
   }
  

}

_____________________

Checking.java

public class Checking extends Account {

  
   public Checking(int account_number) {
       super(account_number);
   }

   @Override
   public int getAccountNumber() {
       return account_number;
   }

   @Override  
   public double getBalance() {
       return balance;
   }

   @Override
   public void getAccInfo() {
       System.out.println(\"Checking Account Information \"+getAccountNumber()+\" and the balance $\"+getBalance());

   }

}

______________________

Savings.java

public class Savings extends Account {

   private double rate;
  
   public Savings(int account_number, double rate) {
       super(account_number);
       this.rate = rate;
   }

   @Override
   public int getAccountNumber() {
  
       return account_number;
   }

   @Override
   public double getBalance() {
      
       return balance;
   }

   @Override
   public void getAccInfo() {
   System.out.println(\"Savings Account Information \"+getAccountNumber()+\" and the balance $\"+getBalance()+\" Rate:\"+rate);

   }

}

___________________________

AccountArray.java

public class AccountArray {

   public static void main(String[] args) {
       Account arr[]= new Account[10];
       arr[0]= new Checking(111);
       arr[0].setBalance(3000);
       arr[1]=new Savings(123,3.5);
       arr[1].setBalance(2000);
       arr[2]=new Checking(222);
       arr[2].setBalance(1500);
       arr[3]=new Savings(234,4.5);
       arr[3].setBalance(1200);
       arr[4]=new Checking(333);
       arr[4].setBalance(900);
arr[5]=new Savings(345,5.5);
arr[5].setBalance(3500);
arr[6]=new Checking(444);
arr[6].setBalance(4000);
arr[7]=new Savings(456,3.6);
arr[7].setBalance(4500);
arr[8]=new Checking(555);
arr[8].setBalance(4200);
arr[9]=new Savings(567,3.7);
arr[9].setBalance(4500);

       for(int i=0;i<arr.length;i++)
       {
           arr[i].getAccInfo();
       }

   }

}

________________________

Output:

Checking Account Information 111 and the balance $3000.0
Savings Account Information 123 and the balance $2000.0 Rate:3.5
Checking Account Information 222 and the balance $1500.0
Savings Account Information 234 and the balance $1200.0 Rate:4.5
Checking Account Information 333 and the balance $900.0
Savings Account Information 345 and the balance $3500.0 Rate:5.5
Checking Account Information 444 and the balance $4000.0
Savings Account Information 456 and the balance $4500.0 Rate:3.6
Checking Account Information 555 and the balance $4200.0
Savings Account Information 567 and the balance $4500.0 Rate:3.7

______Thank You

Write an application named AccountArray in which you enter data for a mix of 10 Checking and Savings accounts. Use a for loop to display the data. Save the file
Write an application named AccountArray in which you enter data for a mix of 10 Checking and Savings accounts. Use a for loop to display the data. Save the file
Write an application named AccountArray in which you enter data for a mix of 10 Checking and Savings accounts. Use a for loop to display the data. Save the file

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site