Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using de following class. 1) ReadAccounts class must read and print out the sum of all balances and the average. From the file(accountsData.bin). 2) WriteAccounts

Using de following class.

1) ReadAccounts class must read and print out the sum of all balances and the average. From the file(accountsData.bin).

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

//////AccountRecord.java//////

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 AccountRecord

/////////ReadAccounts.java/////////

import java.io.BufferedReader; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.FileInputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream;

public class ReadAccounts {

public static void main(String[] args){

AccountRecord accountRecord = null;

try{

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

ObjectInputStream inputStream= new ObjectInputStream(fileInput);

accountRecord = (AccountRecord) inputStream.readObject();

inputStream.close();

} catch(IOException i){

System.out.println("IO Exception");

}catch(ClassNotFoundException c){

System.out.println("Class not found");

}

System.out.println("Record");

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

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

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

}

}

///////////WrriteAccounts.java/////////////

import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.FileInputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Scanner;

public class WriteAccounts {

public static void main(String[] args){

AccountRecord accountRecord = new AccountRecord(12345, "David", 750.00);

try{

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

ObjectOutputStream outputStream= new ObjectOutputStream(output);

outputStream.writeObject(accountRecord);

outputStream.close();

output.close();

}catch (IOException i){

System.out.println("IO Exception");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago