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

When you borrow money to buy a house, a car, or for some other purpose, you repa

ID: 3550634 • Letter: W

Question

When you borrow money to buy a house, a car, or for some other purpose, you repay the loan by making periodic payments over a certain time. Of course the lending company will charge interest on the loan. Every periodic payment consists of the interest on the loan and the payment toward the principal amount. To be specific, suppose that you borrow $1000 at the interest rate of 7.2% per year and the payments are monthly. Suppose that your monthly payment is $25. The interest is 7.2% per year and the payments are monthly, so the interest rate per month is 7.2 / 12 = 0.6%. The first month

Explanation / Answer

//Write a program that accepts as input, the loan amount, the interest rate per year, and the monthly payment.
//(Enter the interest rate as a percentage. For example, if the interest rate is 7.2% per year, then enter 7.2.)
//The program then outputs the number of months it would take to repay the loan.
import java.util.*;
public class payment_calculator
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
double loan_amount;
double interest_rate_per_year;
double monthly_interest;
double monthly_payment;
int number_of_months = 0;
System.out.println("Enter the loan amount :");
loan_amount = in.nextDouble();
System.out.println("Enter the interest rate: ");
interest_rate_per_year = in.nextDouble();
System.out.println("Enter the monthly payment :");
monthly_payment = in.nextDouble();
monthly_interest = interest_rate_per_year*0.01 / 12;
while(loan_amount>=0)
{
double princ = monthly_payment - loan_amount*monthly_interest;
if(princ < 0)
{
System.out.println("monthly payment is too low and with this monthly payment the loan amount could not be repaid");
break;
}
loan_amount = loan_amount - princ;
number_of_months++;
} // end loan amount method;
if(number_of_months>0)
System.out.println("it takes approximately " + number_of_months + " months to repay the loan ");
} //end main method
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote