Question: The Loan class in Listing 10.2 does not implement Serializable. Rewrite the Loan class to implement Serializable. Write a program that creates five Loan objects
The Loan class in Listing 10.2 does not implement Serializable. Rewrite the Loan class to implement Serializable. Write a program that creates five Loan objects and stores them in a file named Exercise17_06.dat.
Listing


1 public class Loan { private double annualInterestRate; 2 private int numberofYears; 3 private double loanAmount; private java.util.Date loanDate; 4 6 /** Default constructor */ public Loan() { this(2.5, 1, 1000); 10 11 /** Construct a loan with specified annual interest rate, 12 13 number of years, and loan amount */ public Loan(double annualInterestRate, int numberOfYears, double loanAmount) { this. annualInterestRate = annualInterestRate; this.number0fYears = number0fYears; this. loanAmount = loanAmount; loanDate - new java.util.Date(); 14 15 16 17 18 19 20 21 22 23 /** Return annualInterestRate */ public double getAnnualInterestRate() { return annualInterestRate; 24 25 26 27 28 29 30 /** Set a new annualInterestRate */ public void setAnnualInterestRate(double annualInterestRate) { this. annualInterestRate = annualInterestRate; 31 32 33 /** Return numberofYears */ public int getNumberofYears () { return number0fYears; 34 35 36 37 38 /** Set a new numberOfYears */ public void setNumberofYears(int numberofYears) { this.numberofYears = number0fYears; 39 40 41 42 43 /** Return loanAmount */ public double getLoanAmount () { return loanAmount; 44 45 46 47 48 /** Set a new 1loanAmount */ public void setLoanAmount (double loanAmount) { this. loanAmount = loanAmount; 49 50 51 52 /** Find monthly payment */ public double getMonthlyPayment() { double monthlyInterestRate = annualInterestRate / 1200; double monthlyPayment = loanAmount * monthlyInterestRate / (1 - (1 / Math.pow(1i + monthlyInterestRate, number0fYears * 12))); return monthlyPayment; 53 54 55 56 57 58 59 60 61 /** Find total payment */ public double getTotal Payment () { double totalPayment = getMonthlyPayment () * numberofYears * 12; return totalPayment; 62 63 64 65 66 67 /** Return loan date */ public java.util.Date getloanDate() { return loanDate; 68 69 70 71 }
Step by Step Solution
3.46 Rating (169 Votes )
There are 3 Steps involved in it
Output On execution the Exercise 196dat file gets generat... View full answer
Get step-by-step solutions from verified subject matter experts
