Question: I need help finishing my class called LoanManager. LoanManager class should be able to load the ArrayList instance variable with data from the text file
I need help finishing my class called LoanManager. LoanManager class should be able to load the ArrayList instance variable with data from the text file in which the collection of loans was saved during the previous session. As such, the user can work with a collection of loans across sessions. I need to have the superclass Loan implement the Comparable interface. Here, you may assume that no loan applicant has more than one loan in the collection.
Code that I need to finish is below. The main code I have done is below the following code.
-----
public class LoanManager { private ArrayList
-----------
Finished code for my abstract class is below (this is already complete).
----------
Loan.java public abstract class Loan { protected String name; // the applicants name protected double interestRate; // the annual interest rate protected int length; // the length of the load in years protected double principle; // the principle protected double monthlyPayment; // the monthly payment
public Loan (String name, double rate, int years, double amount ) { // constructor this.name = name; this.interestRate = rate; this.length = years; this.principle = amount; }
public String process () { return name; // call method calcMonthlyPayment()
// call method makeSummary()
// return the summary
} abstract public void calcMonthPayment (); // an abstract method
public String makeSummary () { return name; // make and return a summary on the loan } public String toString() { return "Loan"; } } SimpleLoan.java public class SimpleLoan extends Loan { public SimpleLoan(String name, double rate, int years, double amount) { super(name, rate, years, amount);
// TODO Auto-generated constructor stub
} ouble monthlyPayment; public void calcMonthPayment () { // calculate the monthly payment using the appropriate formula
// assign the result to the data field monthlyPayment monthlyPayment = (super.principle * ( super.interestRate*(super.length+1) ))/super.length; //System.out.println("Helloooo"+amount); } public String toString() { return "Simple Interest Loan "+monthlyPayment; } public static void main(String args[]){ SimpleLoan s1 = new SimpleLoan("Anita", 8.35, 20, 969000); s1.calcMonthPayment(); System.out.println(s1.toString()); } } AmortizedLoan.java public class AmortizedLoan extends Loan { public AmortizedLoan(String name, double rate, int years, double amount) { super(name, rate, years, amount); // TODO Auto-generated constructor stub
} double monthlyPayment = 0.0; public void calcMonthPayment () { // calculate the monthly payment using the appropriate formula // assign the result to the data field monthlyPayment double n = (1+super.interestRate)*super.length; monthlyPayment = (super.principle * super.interestRate * n)/(n-1); }
public String toString() { return "Full Amortized Loan "+monthlyPayment; } public static void main(String args[]){ AmortizedLoan s1 = new AmortizedLoan("Anita", 8.35, 10, 1000); s1.calcMonthPayment(); System.out.println(s1.toString());
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
