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

Really need your help please... You should now have 4 classes that you built in

ID: 3855288 • Letter: R

Question

Really need your help please...

You should now have 4 classes that you built in MP #1. They are: Account, Person, Customer and the AccountList. These 4 classes should be complete and Tested. Now we are going to make these classes talk to Files. We are going to read and write data to files for these business classes. There are only 2 classes that we need to tie to files. They are: Customer and Account. Part A:(Tie 2 Business Classes to Files) – Let’s start with the Account class.

Let’s make it so that we can look up and find an Account in the “Accounts.txt” file. The Accounts are organized by Account No. So we should be able to look in the File for AcctNo “90001”, and it should give us back all the data for that account, like, AcctNo, CID, Type and Balance, etc. So we will need to read from the “Accounts.txt” file and select the AcctNo “90001”. The File is delimited by “:”(colons). Take a look at the file.

Account:

Customer:

Code for testing ‘Select’ that goes in main:

Account a1 = new Account();

a1.select(“90001”);

a1.display();

Now do the same for the Customer class.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here's what I got...

public class Customer2 extends Person2{
//Properties
public int password;
public int customerID;
public AccountList2 list;
//Constructors
public Customer2(){
super();
list = new AccountList2();
password = 0;
customerID = 0;
}
public Customer2(int pw, int cid ,String fn, String ln, String addr, String em, AccountList2 li){
super(fn, ln, addr, em);
password = pw;
list = li;
customerID = cid;
}
//Behaviors
public void setPw(int pw){
password = pw;
}
public int getPw(){
return password;
}
public void setList(AccountList2 li){
list = li;
}
public AccountList2 getList(){
return list;
}
public void setCid(int cid){
customerID = cid;
}
public int getCid(){
return customerID;
}
public void display(){
System.out.println("");
System.out.println("Password: " + getPw());
System.out.println("Customer ID: " + getCid());
super.display();
list.display();
}
public static void main(String[] args){
Customer2 c2;
c2 = new Customer2();
c2.display();
Customer2 c3;
c3 = new Customer2(9999,3006,"Bill","Gates","Washington","bgates@msn.com", new AccountList2());
c3.display();
}
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class Account2{
//Properties
private int accountNo;
private int customerId;
private String accountType;
private double balance;
//Constructors
public Account2(){
accountNo = 0;
customerId = 0;
accountType = "";
balance = 0.0;
}
public Account2(int acc, int cid, String accType, double bal){
accountNo = acc;
customerId = cid;
accountType = accType;
balance = bal;
}
//Behaviors
public void setAccNo(int acc){
accountNo = acc;
}
public int getAccNo(){
return accountNo;
}
public void setCid(int cid){
customerId = cid;
}
public int getCid(){
return customerId;
}
public void setAccType(String accType){
accountType = accType;
}
public String getAccType(){
return accountType;
}
public void setBal(double bal){
balance = bal;
}
public double getBal(){
return balance;
}
public void display(){
System.out.println("===================== ");
System.out.println("Account Number: " + getAccNo());
System.out.println("Customer ID: " + getCid());
System.out.println("Account Type: " + getAccType());
System.out.println("Balance: $" + getBal());
}
public static void main(String[] args){
Account2 a2;
a2 = new Account2(90000,3003,"SAV",8855.90);
a2.display();
Account2 a3;
a3 = new Account2(90001,3003,"CHK",786.54);
a3.display();
Account2 a4;
a4 = new Account2(90002,3001,"SAV",9654.13);
a4.display();
Account2 a5;
a5 = new Account2(90005,3006,"MMA",700356.23);
a5.display();
}
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.io.*;
import java.util.StringTokenizer;
public class GetData2{
public String data = "";
public String getData2(){
return data;
}
public GetData2(int accountNo, int customerId){
try{
int s1;
File f1 = new File(customerId);
FileInputStream fis = new FileInputStream(f1);
BufferedReader bin = new BufferedReader(new InputStreamReader(fis));
while(true){
s1 = bin.readLine();
if(s1 == null)
break;
System.out.println(s1);
StringTokenizer tok = new StringTokenizer(s1, ":");
String token = tok.nextToken();
System.out.println(token);
if(token.equals(accountNo)){
data = s1;
break;
}
}
}
catch(IOException ie){
System.out.println(ie);
}
}
public static void main(String[] args){
String token;
GetData2 gd = new GetData2("90000","Accounts.txt");
String d = gi.getData2();
System.out.println(d);
StringTokenizer tok = new StringTokenizer(d, ":");
token = token.nextToken();
System.out.println("Account Number: " + token);
token = token.nextToken();
System.out.println("Customer ID: " + token);
token = token.nextToken();
System.out.println("Account Type: " + token);
token = token.nextToken();
System.out.println("Balance: " + token);
}
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Thanks in advance!

Explanation / Answer

public class Customer2 extends Person2{
//Properties
public int password;
public int customerID;
public AccountList2 list;
//Constructors
public Customer2(){
super();
list = new AccountList2();
password = 0;
customerID = 0;
}
public Customer2(int pw, int cid ,String fn, String ln, String addr, String em, AccountList2 li){
super(fn, ln, addr, em);
password = pw;
list = li;
customerID = cid;
}
//Behaviors
public void setPw(int pw){
password = pw;
}
public int getPw(){
return password;
}
public void setList(AccountList2 li){
list = li;
}
public AccountList2 getList(){
return list;
}
public void setCid(int cid){
customerID = cid;
}
public int getCid(){
return customerID;
}
public void display(){
System.out.println("");
System.out.println("Password: " + getPw());
System.out.println("Customer ID: " + getCid());
super.display();
list.display();
}
public static void main(String[] args){
Customer2 c2;
c2 = new Customer2();
c2.display();
Customer2 c3;
c3 = new Customer2(9999,3006,"Bill","Gates","Washington","bgates@msn.com", new AccountList2());
c3.display();
}
}