Required Components: A Java class with a main method. A second Java class that r
ID: 3881631 • Letter: R
Question
Required Components: A Java class with a main method. A second Java class that represents a Loan. Use the Eclipse IDE. Scenario/Information: For most home loans, there are three main values that represent the state of the: the principal (total amount loaned), interest rate (usually stored as annual rate), and total term (in years) that the homeowner has until the loan should be fully repaid. If these three values are known, then other characteristics about the loan can be calculated. For example: . Monthly Rate - Annual Rate/12 Total Months Total Term * 12 Monthly Payment = Principal * Monthly Rate/ (1-(1 + Monthly Rate) Total Months)) What to do: Write a new simple Java program with Eclipse using a main method. The main method should simply declare a loan object and pass the loan object initial values for the principal, rate (APR) and term (years) It should also call a method of the Loan class to get and print the monthly payment to the console. The Loan class should include field variables for each of the basic loan values (principal, rate - APR, and term in years), two constructors (a default no-parameter constructor and a second constructor which allows all three values to be passed in to the object), getters and setters for each field variable, and a method that calculates and returns the monthly payment. Also include methods that will return the total months and monthly rate.Explanation / Answer
Loan.java
package loanInterest;
public class Loan {
private double principal;
private double interestRate;
private double term;
/**
* Constructor with parameters
* @param principal
* @param interestRate
* @param term
*/
public Loan(double principal, double interestRate, double term) {
this.principal = principal;
this.interestRate = interestRate;
this.term = term;
}
/**
* Default constructor
*/
public Loan(){
}
/*
* Getters and setters for all the variables
*/
public double getPrincipal() {
return principal;
}
public void setPrincipal(double principal) {
this.principal = principal;
}
public double getInterestRate() {
return interestRate;
}
public void setInterestRate(int interestRate) {
this.interestRate = interestRate;
}
public double getTerm() {
return term;
}
public void setTerm(int term) {
this.term = term;
}
/**
* @return monthly payment
* Calculates monthly payment for the given term and interest rate
*/
public double monthlyPayment(){
double monthlyRate= interestRate/(12*100);
double totalMonths=term*12;
double montlyPayment=(principal*monthlyRate*Math.pow(1+monthlyRate,totalMonths))/(Math.pow(1+monthlyRate,totalMonths)-1);
return Math.round(montlyPayment);
}
}
TestLoan.java contailns main method
package loanInterest;
public class TestLoan {
public static void main(String[] args) {
Loan testLoan=new Loan(1000000,11,3);
System.out.println("Monthly Payment: "+testLoan.monthlyPayment());
}
}
Sample output
Monthly Payment: 32739.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.