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

Java public class Account extends Main { // data fields enum AccountType{Savings

ID: 3881312 • Letter: J

Question

Java

public class Account extends Main {

// data fields

enum AccountType{Savings, CreditCard, Checking, Business;}

public Account (double d, String CustomerID, double MaxCredit, String tokens, String BName, String BID, String CreditNo, String DebitNo, double ACCBalance, int ACCNumber)

{

this.ACCNumber = ACCNumber;

this.CustomerID = CustomerID;

this.ACCBalance = ACCBalance;

this.DebitNo = DebitNo;

this.BName = BName;

this.BID = BID;

this.CreditNo = CreditNo;

this.MaxCredit = MaxCredit;

}

private int ACCNumber;

private double ACCBalance;

private String CustomerID;

private String DebitNo;

private String BName;

private String BID;

private String CreditNo;

private double MaxCredit;

//Savings Account

public void Savings(int ACCNumber, String CustomerID, double ACCBalance)

{

this.ACCNumber = ACCNumber;

this.CustomerID = CustomerID;

this.ACCBalance = ACCBalance;

}

//Checking Account

public void Checkings(int ACCNumber, String CustomerID, double ACCBalance, String DebitNo)

{

this.ACCNumber = ACCNumber;

this.CustomerID = CustomerID;

this.ACCBalance = ACCBalance;

this.DebitNo = DebitNo;

}

//Business Account

public void Business (int ACCNumber, String CustomerID, double ACCBalance, String BName, String BID)

{

this.ACCNumber = ACCNumber;

this.CustomerID = CustomerID;

this.ACCBalance = ACCBalance;

this.BName = BName;

this.BID = BID;

}

//Credit Card Account

public void CreditCard(String CustomerID, String CreditNo, double ACCBalance, double MaxCredit)

{

this.CustomerID = CustomerID;

this.CreditNo = CreditNo;

this.ACCBalance = ACCBalance;

this.MaxCredit = MaxCredit;

}

public String getCreditNo() {return CreditNo;}

public void setCreditNo(String CreditNo) {this.CreditNo = CreditNo;}

public double getMaxCredit() {return MaxCredit;}

public void setMaxCredit(double MaxCredit) {this.MaxCredit = MaxCredit;}

public String getDebitNo() {return DebitNo;}

public void setDebitNo(String DebitNo) {this.DebitNo = DebitNo;}

public String getBID() {return BID;}

public void setBID(String BID) {this.BID = BID;}

public String getBName() {return BName;}

public void setBName(String BName) {this.BName = BName;}

public String getCustomerID() {return CustomerID;}

public void setCustomerID(String CustomerID) {this.CustomerID = CustomerID;}

public int getACCNumber() {return ACCNumber;}

public void setACCNumber(int ACCNumber) {this.ACCNumber = ACCNumber;}

public double getACCBalance() {return ACCBalance;}

public void setACCBalance(double ACCBalance) {this.ACCBalance = ACCBalance;}

public String toString() {

return "Account [ACCNumber=" + ACCNumber + ", ACCBalance=" + ACCBalance + ", CustomerID=" + CustomerID

+ ", DebitNo=" + DebitNo + ", BName=" + BName + ", BID=" + BID + ", CreditNo=" + CreditNo

+ ", MaxCredit=" + MaxCredit + "]";

}

}

public class Customer extends Main{

private String ID;

private String LName;

private String FName;

private String Address;

private String City;

public Customer(String ID, String LName, String FName, String Address, String City)

{

this.ID =ID;

this.LName = LName;

this.FName = FName;

this.Address = Address;

this.City = City;

}

public Customer(String string, String string2, String string3, String string4) {

// TODO Auto-generated constructor stub

}

public String getID() {return ID;}

public void setID(String iD) {ID = iD;}

public String getLName() { return LName;}

public void setLName(String LName) {this.LName = LName;}

public String getFName() {return FName;}

public void setFName(String FName) {this.FName = FName;}

public String getAddress() {return Address;}

public void setAddress(String Address) {this.Address = Address;}

public String getCity() {return City;}

public void setCity(String City) {this.City = City;}

public String toString() {

return "Customer [ID=" + ID + ", LName=" + LName + ", FName=" + FName + ", Address=" + Address + ", City=" + City

+ "]";

}}


import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import java.util.Scanner;

public class Main {

ArrayList<Customer> customers;

ArrayList<Account> accounts;

  

public Main() {

customers = new ArrayList<>();

accounts = new ArrayList<>();

  

}

  

public void getDataFromFile(String dataset){

Q:In the main class, write a method getDataFromFile to read data frmo a given file. This method should read data frmo the file, create appropriate objects for teh customer and account, save the data into an array.

Write a method displayAccounts that displays all customers and their accounts information Make sure to properly format the output.

main : this method should be used to call all other methods and formatting output if necessary.

Use Scanner not the BufferReader.

Explanation / Answer

public class Account {

   // data fields

   private int ACCNumber;

   private double ACCBalance;

   private String CustomerID;

   private String DebitNo;

   private String BName;

   private String BID;

   private String CreditNo;

   private double MaxCredit;

   //Savings Account

   public Account(int ACCNumber, String CustomerID, double ACCBalance) {

   this.ACCNumber = ACCNumber;

   this.CustomerID = CustomerID;

   this.ACCBalance = ACCBalance;}

   //Checking Account

   public Account(int ACCNumber, String CustomerID, double ACCBalance, String DebitNo)

   {

   this.ACCNumber = ACCNumber;

   this.CustomerID = CustomerID;

   this.ACCBalance = ACCBalance;

   this.DebitNo = DebitNo;

   }

   //Business Account

   public Account (int ACCNumber, String CustomerID, double ACCBalance, String BName, String BID)

   {

   this.ACCNumber = ACCNumber;

   this.CustomerID = CustomerID;

   this.ACCBalance = ACCBalance;

   this.BName = BName;

   this.BID = BID;

   }

   //Credit Card Account

   public Account(String CustomerID, String CreditNo, double ACCBalance, double MaxCredit)

   {

   this.CustomerID = CustomerID;

   this.CreditNo = CreditNo;

   this.ACCBalance = ACCBalance;

   this.MaxCredit = MaxCredit;

   }

   public String getCreditNo() {return CreditNo;}

   public void setCreditNo(String CreditNo) {this.CreditNo = CreditNo;}

   public double getMaxCredit() {return MaxCredit;}

   public void setMaxCredit(double MaxCredit) {this.MaxCredit = MaxCredit;}

   public String getDebitNo() {return DebitNo;}

   public void setDebitNo(String DebitNo) {this.DebitNo = DebitNo;}

   public String getBID() {return BID;}

   public void setBID(String BID) {this.BID = BID;}

   public String getBName() {return BName;}

   public void setBName(String BName) {this.BName = BName;}

   public String getCustomerID() {return CustomerID;}

   public void setCustomerID(String CustomerID) {this.CustomerID = CustomerID;}

   public int getACCNumber() {return ACCNumber;}

   public void setACCNumber(int ACCNumber) {this.ACCNumber = ACCNumber;}

   public double getACCBalance() {return ACCBalance;}

   public void setACCBalance(double ACCBalance) {this.ACCBalance = ACCBalance;}

   /* (non-Javadoc)

   * @see java.lang.Object#toString()

   */

   @Override

   public String toString() {

       return "Account [ACCNumber=" + ACCNumber + ", ACCBalance=" + ACCBalance + ", CustomerID=" + CustomerID

               + ", DebitNo=" + DebitNo + ", BName=" + BName + ", BID=" + BID + ", CreditNo=" + CreditNo

               + ", MaxCredit=" + MaxCredit + "]";

   }

}

public class Customer{

private String ID;

private String LName;

private String FName;

private String Address;

private String City;

public Customer(String ID, String LName, String FName, String Address, String City)

{

this.ID =ID;

this.LName = LName;

this.FName = FName;

this.Address = Address;

this.City = City;

}

public String getID() {return ID;}

public void setID(String iD) {ID = iD;}

public String getLName() { return LName;}

public void setLName(String LName) {this.LName = LName;}

public String getFName() {return FName;}

public void setFName(String FName) {this.FName = FName;}

public String getAddress() {return Address;}

public void setAddress(String Address) {this.Address = Address;}

public String getCity() {return City;}

public void setCity(String City) {this.City = City;}

/* (non-Javadoc)

* @see java.lang.Object#toString()

*/

@Override

public String toString() {

   return "Customer [ID=" + ID + ", LName=" + LName + ", FName=" + FName + ", Address=" + Address + ", City=" + City

           + "]";

}

}

import java.io.File;

import java.util.ArrayList;

import java.util.Scanner;

public class Main {

   ArrayList<Customer> customers;

   ArrayList<Account> accounts;

   public Main() {

       customers = new ArrayList<>();

       accounts = new ArrayList<>();

   }

  

public void getDataFromFile(String dataset){

       Scanner sc;

       try{

           //file

           File file = new File(dataset);

           //scanner

           sc = new Scanner(file);

           //read line

           while ( sc.hasNextLine()) {

               //split line

               String[] tokens = sc.nextLine().split(" ");

               if (tokens.length > 1) {

               Customer customer = new Customer(tokens[0], tokens[1], tokens[2], tokens[3], tokens[4]);

               customers.add(customer);

               if (tokens[5].equalsIgnoreCase("Checking")){

                   Account account= new Account(Integer.parseInt(tokens[6]), tokens[0], Double.parseDouble(tokens[7]), tokens[8]);

                   accounts.add(account);

               }

               if (tokens[5].equalsIgnoreCase("Savings")){

                   Account account= new Account(Integer.parseInt(tokens[6]), tokens[0],Double.parseDouble( tokens[7]));

                   accounts.add(account);

               }

               if (tokens[5].equalsIgnoreCase("Business")){

                   Account account= new Account(Integer.parseInt(tokens[6]), tokens[0], Double.parseDouble(tokens[7]), tokens[8], tokens[9]);

                   accounts.add(account);

               }

               if (tokens[5].equalsIgnoreCase("CreditCard")){

                   Account account= new Account(tokens[0], tokens[6], Double.parseDouble(tokens[7]), Double.parseDouble(tokens[8]));

                   accounts.add(account);

               }

               }

           }

       }

       catch(Exception e){

           System.err.println(e);

       }

   }

   //prints both arrays using for loop

   public void displayAccounts(){

       for (Customer customer:customers){

           System.out.println(customer.toString());

           for (Account account:accounts){

               if (account.getCustomerID() == customer.getID())

                   System.out.println(account.toString());

           }

       }

   }

   public static void main(String[] args) {

       Main main = new Main();

       //you can change file name here

       main.getDataFromFile("detail.txt");

       main.displayAccounts();

   }

}

detail.txt

C8392380567 Sage Amy PingTingRoad Edmonton Checking 873387 5000 0000-6666-6666-6666

C8954385123 Lee Bob TexacoRoad Calgary Savings 827366 9480

C2389490434 Neil Carson DeerfootTrail Otawa Business 763655 65000 Emporia LLC87-927736

C9384899234 Ko David UnversityDrive Stillwater CreditCard 7667-9899-8776-1234 430 4000

C0930238083 Warren John OgdenRoad Tyler Checking 726615 1230 0000-2222-2222-2222

Sample OutPut:

Customer [ID=C8392380567, LName=Sage, FName=Amy, Address=PingTingRoad, City=Edmonton]

Account [ACCNumber=873387, ACCBalance=5000.0, CustomerID=C8392380567, DebitNo=0000-6666-6666-6666, BName=null, BID=null, CreditNo=null, MaxCredit=0.0]

Customer [ID=C8954385123, LName=Lee, FName=Bob, Address=TexacoRoad, City=Calgary]

Account [ACCNumber=827366, ACCBalance=9480.0, CustomerID=C8954385123, DebitNo=null, BName=null, BID=null, CreditNo=null, MaxCredit=0.0]

Customer [ID=C2389490434, LName=Neil, FName=Carson, Address=DeerfootTrail, City=Otawa]

Account [ACCNumber=763655, ACCBalance=65000.0, CustomerID=C2389490434, DebitNo=null, BName=Emporia, BID=LLC87-927736, CreditNo=null, MaxCredit=0.0]

Customer [ID=C9384899234, LName=Ko, FName=David, Address=UnversityDrive, City=Stillwater]

Account [ACCNumber=0, ACCBalance=430.0, CustomerID=C9384899234, DebitNo=null, BName=null, BID=null, CreditNo=7667-9899-8776-1234, MaxCredit=4000.0]

Customer [ID=C0930238083, LName=Warren, FName=John, Address=OgdenRoad, City=Tyler]

Account [ACCNumber=726615, ACCBalance=1230.0, CustomerID=C0930238083, DebitNo=0000-2222-2222-2222, BName=null, BID=null, CreditNo=null, MaxCredit=0.0]

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