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

Written in C# - Console Applications - Visual Studios 2012 (Please Provide Scree

ID: 3589808 • Letter: W

Question

Written in C# - Console Applications - Visual Studios 2012 (Please Provide Screenshots)

You are to write a program which is going to use inheritance. It should start off with the base classes

Account: contains the string name, int accountnumber, double balance.

Savings: Derived from Account class, it should contain double interest rate.

Checkings: Derived from Account class, it should contain double overdraftlimit.

CreditCard: Derived from Checkings class, it should contain int cardnumber.  

Create a program which will create an array of 3 Savings accounts, 3 Checkings accounts and 3 CreditCards. Create 3 files. Savings.txt, Checkings.txt, CreditCards.txt which contains the information for each and infile the information from the file to the array of the classes. *You will come up with the information in each file*

Make sure to include the method used to infile (make sure to use loops), the way the classes are constructed (inheritance), and the way the the classes are used (make sure the constructor and overloaded constructor is used correctly).

As for the Main, simply do a display of all 3 savings, checkings and creditcards in a neat fashion.

Explanation / Answer

import java.io.*;
import java.util.*;

class Account {
   private String name;
   private int accountnumber;
   private double balance;
   public Account(String nm,int actno,double bal){
        name = nm;
        accountnumber = actno;
        balance = bal;
   }
   public void disp(){
      System.out.println("Name: " + name);
      System.out.println("Account Number: " + accountnumber);
      System.out.println("Balance: " +balance);
   }
}

class Savings extends Account{
    private double intrest_rate;
    public Savings(String nm,int actno,double bal, double intr){
        super(nm,actno,bal);
        intrest_rate = intr;
    }
    public void disp(){
       super.disp();
       System.out.println("Intrest rate: " + intrest_rate);
     
    }  
}

class Checkings extends Account{
    private double overdraft_limit;
    public Checkings(String nm,int actno,double bal, double limit){
        super(nm,actno,bal);
        overdraft_limit= limit;
    }
    public void disp(){
       super.disp();
       System.out.println("Overdraft limit: " + overdraft_limit);
     
    }  
}

class CreditCard extends Checkings{
    private int cardnumber;
    public CreditCard(String nm,int actno,double bal, double limit,int num){
        super(nm,actno,bal,limit);
        cardnumber = num;
    }
    public void disp(){
       super.disp();
       System.out.println("Card Number: " + cardnumber);
     
    }  
}

public class DemoAccount {
public static void main(String[] args){
    
      String name;
      int accountnumber;
      double balance;
      double limit;
      int cardnumber;
      double intrest_rate;
      double overdraft_limit;

      Savings[] s = new Savings[3];
      Checkings[] c = new Checkings[3];
      CreditCard[] ca = new CreditCard[3];
      try {
         File file = new File("Savings.txt");
         Scanner sc = new Scanner(file);
         for (int i = 0; i<3; i++){
            name = sc.next();   //Name will not have spaces
            accountnumber = sc.nextInt();
            balance = sc.nextDouble();
            intrest_rate = sc.nextDouble();
            s[i] = new Savings(name,accountnumber ,balance,intrest_rate);
         }
         for (int i = 0; i<3; i++){
              s[i].disp();       
         }
         File file1 = new File("Checkings.txt");
         sc = new Scanner(file1);
         for (int i = 0; i<3; i++){
            name = sc.next();   //Name will not have spaces
            accountnumber = sc.nextInt();
            balance = sc.nextDouble();
            overdraft_limit = sc.nextDouble();
            c[i] = new Checkings(name,accountnumber ,balance,overdraft_limit);
         }
         for (int i = 0; i<3; i++){
              c[i].disp();       
         }
         File file2 = new File("CreditCards.txt");
         sc = new Scanner(file2);
         for (int i = 0; i<3; i++){
            name = sc.next();   //Name will not have spaces
            accountnumber = sc.nextInt();
            balance = sc.nextDouble();
            overdraft_limit = sc.nextDouble();
            cardnumber = sc.nextInt();
            ca[i] = new CreditCard(name,accountnumber,balance,overdraft_limit,cardnumber );
         }
         for (int i = 0; i<3; i++){
              ca[i].disp();       
         }
      } catch (Exception e){
         e.printStackTrace();
      }
    
     
}
}