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:
- Make the Loan class Serializable
- Instantiate Loan objects representing the first three loans above using the full constructor
- Create an output stream and store the three objects into a binary file using the writeObject method
- Instantiate Loan objects representing the last two loans above using the no-arg constructor, then use setters to update information about those loans
- Append those objects to the output stream created above in step 2
- Close the output stream
- 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.
- Close the input stream
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started