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

You are to create the following 3 classes: Both Savings and Checkings inherit th

ID: 3559949 • Letter: Y

Question

You are to create the following 3 classes:

Both Savings and Checkings inherit the Account class.

The Account class has the following variables:

The Savings has the following variables:

The Checkings as the following variables:

Your program should start off by declaring an array of 5 Checkings and 5 Savings. The number of actual accounts should be kept as we used an array of size 5, but not all 5 will be filled up. In the end after reading in the file, there will be only 2 Savings and 3 Checkings, which is important to know because your loops will only go that amount of times.

There is a file called "Accounts.txt" which has all the information.

Savings Nick 500 1000 1234 2

Checkings Nick 2000 1001 1234 11111 142

Checkings Carlos 10000 1002 1245 33356 841

Savings Emmanuel 247 1003 3041 10

Checkings Edgar 3000 1004 6969 55721 216

Be aware that checkings accounts have more variables than savings accounts because rate is static. Be sure to read in the account type and make the correct class to place it in.

Be able to sort the users based on name, money, or account number.

Create a nice function to display all the users data neatly on the screen so when we sort we can view everything nicely.

Be able to do searching, which is basically going to search based on two variables entered... name and pin.

Do notice that only one person has BOTH a checking and savings account, so for that person, ask which account to go into based on account type.

**this does include inheritance, static variables, infile, arrays, condition statements

Explanation / Answer

Account.java

public class Account {
    String AccountType;
    String Name;
    int Money;
    int Accountnumber;
    int Pin;
    public String print(){
       return new String(" AccountType:"+AccountType+" AccountNumber:"+Accountnumber+" Name:"+Name+" Money:"+Money+" Pin:"+Pin);
    }
}

Savings.java

public class Savings extends Account{
    static int rate = 2;
    public int totalinterest;
  
    public String print(){
       return super.print()+new String(" TotalInterest:"+totalinterest);
    }
  
    public int Search(String name,int pin){
       if(this.Name == name && this.Pin == pin){      
       return 0;}
       return -1;
    }
}


Checkings.java

public class Checkings extends Account {
    int debitnumber;
    int securitycode;
    public String print(){
       return super.print()+new String(" DebitNumber"+debitnumber+" SecurityCode:"+securitycode);
    }
}


Test.java

import java.io.*;
public class Test {
   public static void main(String[] args) throws IOException {
       Checkings []arr = new Checkings[5];
       Savings []arr1 = new Savings[5];
       String [][]str = new String[5][7];
       FileInputStream fis = new FileInputStream("C:\java\basic\Bank\src\Accounts.txt");
       BufferedReader br = new BufferedReader(new InputStreamReader(fis));
       String line = null;
       int i = 0,j=0,k=0,l=0;
       while ((line = br.readLine()) != null) {
           str[i] = line.split(" ");
           if(str[i][0].compareToIgnoreCase("Savings") == 0){
               arr1[j] = new Savings();
               arr1[j].AccountType = str[i][0];
               arr1[j].Name = str[i][1];
               arr1[j].Money = Integer.parseInt(str[i][2]);
               arr1[j].Accountnumber = Integer.parseInt(str[i][3]);
               arr1[j].Pin = Integer.parseInt(str[i][4]);
               arr1[j].totalinterest = Integer.parseInt(str[i][5]);
               j++;
           }
           else{
               arr[k] = new Checkings();
               arr[k].AccountType = str[i][0];
               arr[k].Name = str[i][1];
               arr[k].Money = Integer.parseInt(str[i][2]);
               arr[k].Accountnumber = Integer.parseInt(str[i][3]);
               arr[k].Pin = Integer.parseInt(str[i][4]);
               arr[k].debitnumber = Integer.parseInt(str[i][5]);
               arr[k].securitycode = Integer.parseInt(str[i][6]);
               k++;
           }
           i++;
       }
       Sort(arr1,"name");
       for(i=0;i<2;i++)System.out.println(arr1[i].print());
      
       Sort(arr,"name");
       for(i=0;i<3;i++)System.out.println(arr[i].print());
      
       for(i=0;i<2;i++){
           if(arr1[i].Search("Nick", 1234)==0){
               arr1[i].print();
           }
       }
   }
   public static void Sort(Savings []s,String param){
       Savings s1 = new Savings();
       for(int i=0;i<2;i++){
           for(int j=i;j<2;j++){
               if(param.toLowerCase() == "name"){
                   if(s[i].Name.compareTo(s[j].Name) > 0){
                       swap(s[i], s[j]);
                   }
               }
               else if(param.toLowerCase() == "money"){
                   if(s[i].Money > s[j].Money){
                       swap(s[i],s[j]);
                   }
               }
               else
               {
                   if(s[i].Accountnumber > s[j].Accountnumber)
                   swap(s[i],s[j]);
               }
           }
       }
      
   }
   public static void Sort(Checkings []s,String param){
       for(int i=0;i<3;i++){
           for(int j=i+1;j<3;j++){
               if(param.toLowerCase() == "name"){
                   if(s[i].Name.compareTo(s[j].Name) > 0){
                       swap(s[i], s[j]);
                   }
               }
               else if(param.toLowerCase() == "money"){
                   if(s[i].Money > s[j].Money){
                       swap(s[i],s[j]);
                   }
               }
               else
               {
                   if(s[i].Accountnumber > s[j].Accountnumber)
                   swap(s[i],s[j]);
               }
           }
       }
   }
   public static void swap(Savings s,Savings s2)
   {
       Savings s1 = new Savings();
       s1.Name = s.Name;
       s1.Accountnumber = s.Accountnumber;
       s1.AccountType = s.AccountType;
       s1.Money = s.Money;
       s1.Pin = s.Pin;
       s1.totalinterest = s.totalinterest;
      
       s.Name = s2.Name;
       s.Accountnumber = s2.Accountnumber;
       s.AccountType = s2.AccountType;
       s.Money = s2.Money;
       s.Pin = s2.Pin;
       s.totalinterest = s2.totalinterest;
      
       s2.Name = s1.Name;
       s2.Accountnumber = s1.Accountnumber;
       s2.AccountType = s1.AccountType;
       s2.Money = s1.Money;
       s2.Pin = s1.Pin;
       s2.totalinterest = s1.totalinterest;
   }
   public static void swap(Checkings s,Checkings s2)
   {
       Checkings s1 = new Checkings();
       s1.Name = s.Name;
       s1.Accountnumber = s.Accountnumber;
       s1.AccountType = s.AccountType;
       s1.Money = s.Money;
       s1.Pin = s.Pin;
       s1.debitnumber = s.debitnumber;
       s1.securitycode = s.securitycode;
      
       s.Name = s2.Name;
       s.Accountnumber = s2.Accountnumber;
       s.AccountType = s2.AccountType;
       s.Money = s2.Money;
       s.Pin = s2.Pin;
       s.debitnumber = s2.debitnumber;
       s.securitycode = s2.securitycode;
      
       s2.Name = s1.Name;
       s2.Accountnumber = s1.Accountnumber;
       s2.AccountType = s1.AccountType;
       s2.Money = s1.Money;
       s2.Pin = s1.Pin;
       s2.debitnumber = s1.debitnumber;
       s2.securitycode = s1.securitycode;
   }
}

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