Question: Summary Create a Loan class(in JAVA), instantiate and write several Loan objects to a file, read them back in, and format a report. Project Description

Summary

Create a Loan class(in JAVA), instantiate and write several Loan objects to a file, read them back in, and format a report.

Project Description

This this lab, youll read and write files containing objects of the Loan class. Here are the details of that class:

Instance Variables: customer name (String) annual interest percentage (double) number of years (int) loan amount (double) loan date (String) monthly payment (double) total payments (double)

Methods:

  • getters for all instance variables
  • setters for all instance variables except monthly payment and total payment
  • calculateMonthlyPayment and calculateTotalPayments

The setters for the annual interest percentage, number of years, and loan amount invoke both calculate methods before they exit

The calculate methods compute the named value, then store that amount in the associated instance variable. They are private (helper) methods.

Constructors:

  • a no-arg constructor sets the customer name to a default value, the loan date to no date, and all numeric variables to zero. This method invokes the full constructor
  • a full constructor takes the customer name, annual interest percentage, number of years, loan amount, and loan date. It invokes the appropriate setters, but doesnt need to invoke the calculate methods (why?)

Calculations:

monthly interest rate = annual interest percentage / 1200

monthly payment = (loan amount * monthly interest rate) / (1 Math.pow( (1 + monthly interest rate), (number of years * 12) ) )

total loan payments = monthly payment * number of years * 12

* Note: Round all dollar amounts to 2 decimal places

Here is what you should do in main

Use this data to create five Loan objects

 Annual Interest Loan  Customer Name Percentage Years Amount Loan Date Bob Smith 6.5% 30 318,000 Sep 1, 2015 Alicia Herman 4.2% 15 248,000 Oct 15, 2013 Julie Franciosa 8.5% 10 30,000 Apr 14, 2010 Julio Quiros 15.0% 3 50,000 June 23, 2017 Frank Larsen 8.9% 5 23,000 Mar 8, 2016

Use this summary algorithm for your program:

  1. Make the Loan class Serializable
  2. Instantiate Loan objects representing the first three loans above using the full constructor
  3. Create an output stream and store the three objects into a binary file using the writeObject method
  4. Instantiate Loan objects representing the last two loans above using the no-arg constructor, then use setters to update information about those loans
  5. Append those objects to the output stream created above in step 2
  6. Close the output stream
  7. Create an input stream and read the objects from the binary file above and display in a nicely formatted columnar report
  • Write your code to handle any number of loan objects (i.e., do not assume that there are 5 Loan objects in the file
  • Include in your report the monthly loan payment and total loan payment amounts
  • Display totals for the amount of the loan amounts, monthly payments, and total loan payments.
  1. Close the input stream

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!