Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Table of Contents Jan 23-Server - JavaJava_Review Assignment Java_Review_Assignm

ID: 3878158 • Letter: T

Question

Table of Contents Jan 23-Server - JavaJava_Review Assignment Java_Review_Assignment Scenario/Irformation: 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: 1/4 ·Monthly Rate = Annual Rate/12 Total Term * 12 Total Months 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 months and monthly rate MacBook Air

Explanation / Answer

import java.util.*;
import java.lang.*;


class Loan
{
private double principle;
private double rate;
private int term;

//default constructor
public Loan()
{
principle = 0.0;
rate = 0.0;
term = 0;
}

//argument constructor
public Loan(double principle,double rate,int term)
{
this.principle = principle;
this.rate = rate;
this.term = term;
}

//set and get methods for principle,rate and term
public void setPrinciple(double principle)
{
this.principle = principle;
}
public double getPrinciple()
{
return principle;
}

public void setRate(double rate)
{
this.rate = rate;
}
public double getRate()
{
return rate;
}

public void setTerm(int term)
{
this.term = term;
}
public int getTerm()
{
return term;
}


public double monthlyPayment() // compute monthly payment
{
return principle*(rate/12)/(1-Math.pow((1+rate/12),(-term*12)) );
}

public int totalMonths()
{
return term*12;
}
public double monthlyRate()
{
return rate/12;
}
}
class TestLoan
{
public static void main (String[] args)
{
Loan l = new Loan(500000,6.5,30);

System.out.println("Monthly Loan Payment : $"+ l.monthlyPayment());

System.out.println("Total Months : "+l.totalMonths());

System.out.println("Monthly Rate : "+l.monthlyRate());
}
}

Output:

Monthly Loan Payment : $270833.3333333333
Total Months : 360
Monthly Rate : 0.5416666666666666