Question: Java Programing: Need help adding what's marked in bold from part 1 and 2 to the programs. 1. (Java) Make public class called ReadAccounts. This

Java Programing: Need help adding what's marked in bold from part 1 and 2 to the programs.

1. (Java) Make public class called ReadAccounts. This class will read a file ("accountsData.bin") where the data is "Byte-based stream". Once you have read the file, print the total sum of the balance and their average (Use the AccountRecord class mentioned below(attachments)).

2.(Java) WriteAccounts class must ask various account information and save the data entered. From the file(accountsData.bin).

Code:

//AccountRecord

package edu.pupr.FinalTest;

import java.io.Serializable;

public class AccountRecord implements Serializable {

private int accountNo;

private String fullName;

private double balance;

// initialize a record

public AccountRecord(int acctNo, String name, double bal) { setAccountNo( acctNo );

setFullName( name );

setBalance( bal );

} // end four-argument AccountRecord constructor

// set account number no

public void setAccountNo( int acctNo ) {

accountNo = acctNo;

} // end method setAccountNo

// get account number no

public int getAccountNo() {

return accountNo;

} // end method getAccountNo

// set full name

public void setFullName( String name ) {

fullName = name;

} // end method setFullName

// get full name

public String getFullName() {

return fullName;

} // end method getFullName

// set balance

public void setBalance( double bal ) {

balance = bal;

} // end method setBalance

// get balance

public double getBalance() {

return balance;

} // end method getBalance

} // end class AccountRecordn

//ReadAccounts

package edu.pupr.FinalTest;

import java.io.IOException;

import java.io.FileInputStream;

import java.io.ObjectInputStream;

public class ReadAccounts {

public static void main(String[] args){

//creatws new Account Record

AccountRecord accountRecord = null;

try{

//Creates object output stream for axcountData.bin

FileInputStream fileInput= new FileInputStream("accountsData.bin");

ObjectInputStream inputStream= new ObjectInputStream(fileInput);

accountRecord = (AccountRecord) inputStream.readObject();

inputStream.close();

fileInput.close();

}

catch(IOException i)

{

System.out.println("Error");

}

catch(ClassNotFoundException c)

{

System.out.println("Not found");

}

System.out.println("****Account Record****");

System.out.println("Account Number: " + accountRecord.getAccountNo());

System.out.println("Name: " + accountRecord.getFullName());

System.out.println("Balance: " + accountRecord.getBalance());

}

}

//WriteAccounts

package edu.pupr.FinalTest;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectOutputStream;

public class WriteAccounts {

public static void main(String[] args){

// Creates new AccountRecords

AccountRecord accountRec = new AccountRecord(1212121, "Sample", 5000.00); //* must ask various account information and save the data entered*

try{

//Create object output

FileOutputStream fileOutput=new FileOutputStream("accountsData.bin");

ObjectOutputStream outStream= new ObjectOutputStream(fileOutput);

//Writing data to accountData.bin

outStream.writeObject(accountRec);

outStream.close();

fileOutput.close();

}

catch (IOException i){

System.out.println("Error");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!