I need help writing this in Java At some time everyone event

I need help writing this in Java.

At some time, everyone eventually borrows money, perhaps for a new car, a house, or to fi nance a start-up business. The amount of interest that you pay over the life of a loan may surprise you. For a 30-year, $200,000 loan at 6% annual interest, the total interest is more than $230,000.

Write a program that calculates the monthly payment as well the portion of each monthly payment that is interest. The program should prompt the user for

1. the amount borrowed in dollars,

2. the annual interest rate as a percentage, and

3. the term of the loan in years.

The program should be able to run any number of times with different data. The monthly payment is calculated with the following formula:

where amount is the amount borrowed in dollars, m is the total number of monthly payments, and rate is the monthly interest rate. For example, if the annual interest rate is 6%, and the term of the loan is 30 years, then m =12 x 30 = 360, and rate = .06/12 = .005 or 0.5%.

The amount of the loan cannot exceed $1,000,000; the interest is given as a percentage between 2.0 and 15.0 inclusive, for example, 6.5 or 5.75; and the term of the loan is no more than 30 years. Your program should check input to ensure that these restrictions are met.

Your program should display the monthly payment followed by a month-bymonth table showing the interest and principal paid each month. The interest paid each month equals the rate times the remaining balance of the loan. The remainder of the monthly payment goes to principal.

The loan balance begins with the amount borrowed. The remaining balance of the loan should be updated each month by subtracting the principal paid that monthfrom the previous remaining loan balance. For convenience, round interest to the nearest dollar. This can be accomplished with

Math.Round(interest).

Finally, display the total amount of interest, rounded to the nearest dollar, paid over the life of the loan.

Solution

import java.util.Scanner;

public class InterestCalculator {

  

   public static void main(String args[])

   {

       Scanner in = new Scanner(System.in);

       System.out.println(\"Enter the amount borrowed:\");

       double amount = in.nextDouble();

       System.out.println(\"Enter the annual interest rate:\");

       double rate = in.nextDouble();

       System.out.println(\"Enter the tenure of loan:\");

       int period = in.nextInt();

       double amountLeft = amount;

       System.out.println(\"Payment\\t\\tPrincipal\\tInterest\");

       for(int i = 0; i < period*12; i++)

       {

           double payment = monthlyPayment(amountLeft, rate, period);

           double interest = rate*amountLeft/(1200.0);

           double principal = payment - interest;

           System.out.println(payment + \"\\t\" + principal + \"\\t\" + interest);

           amountLeft -= principal;

       }

       monthlyPayment(amount, rate, period);

   }

  

public static double monthlyPayment(double amount, double rate, int period)

   {

       int m = period*12;

       double r = rate/1200.0;

       double temp = 1.0 - Math.pow((1/(1+r)),m);

       double payment = amount*r/temp;

       return payment;

   }

}

I need help writing this in Java. At some time, everyone eventually borrows money, perhaps for a new car, a house, or to fi nance a start-up business. The amoun
I need help writing this in Java. At some time, everyone eventually borrows money, perhaps for a new car, a house, or to fi nance a start-up business. The amoun

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site