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

LoanSerializable.java, WriteLoanObjects.java, ReadLoadObjects.java, Date.java Wr

ID: 3775843 • Letter: L

Question

LoanSerializable.java, WriteLoanObjects.java, ReadLoadObjects.java, Date.java Write the LoanSerializable.java class to implement Serializable. Write a program WriteLoanObjects.java that creates five Loan objects and stores them in a file named LoanObjects.dat. (Restore objects from a file). Write a program ReadLoanObjects.java that reads the Loan objects from the file and displays the total loan amount. Suppose you don't know how many Loan objects are there in the file, use EOFException to end the loop. Methods and attributes of Loan class General instructions Use try...catch blocks

Explanation / Answer

Code to copy:

// class file name: writeobjects.class

// file name: wirteobjects.java

import java.io.*;

/**

* This class file writes a number of Loan objects to a file Objects.dat, to be read

* from another class Lab09ReadObjects.

*/

public class Lab09WriteObjects {

public static void main(String[] args) throws IOException {

    ObjectOutputStream output = new ObjectOutputStream(

      new FileOutputStream("Objects.dat"));

    output.writeObject(new Loan(2.5, 5, 100000));

    output.writeObject(new Loan(3.5, 5, 200000));

    output.writeObject(new Loan(4.5, 5, 300000));

    output.writeObject(new Loan(5.5, 5, 400000));

    output.writeObject(new Loan(6.5, 5, 500000));

    output.close();

    System.out.println("5 Loan Objects written to file Objects.dat");

}

}

// file name: Loan.class

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

// file name: loan.ctxt

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

// file name:loan.java

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

//file name: Testloan.class

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

// file name: TestLoan.ctxt

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

//file name: TestLoan.java

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