Question: Java using IntelliJ Loan Payments Problem I am trying to solve: Write a program that calculates the monthly payments you would have to make over
Java using IntelliJ
Loan Payments
Problem I am trying to solve:
Write a program that calculates the monthly payments you would have to make over a given number of years to pay off a loan at a given interest rate compounded continuously, taking the number of years t, the principal P, and the annual interest rate r as command-line arguments. The desired value is given by the formula Pe^rt. Use Math.exp().
My Code:
public class LoanPayment { public static void main(String args[]){ //initial value deposited double p = Double.parseDouble(arg[0]); //time in years double t = Double.parseDouble(arg[1]); //annual interest rate double r = Double.parseDouble(arg[2]); //calculate rate % r = r/100; //calculate compound interest double compounded = p * Math.exp(r*t); //calculate monthly capital value double monthly = monthlyCapital + compounded/(t*12); //calculate months int months = (int)(t*12.0); for(int i = 0; i < months; i++;){ p = p - monthlyCapital; //print the values System.out.println("Month %2d payment %.2f remaining principal %.2f interest %.2f, i+1 , monthly, p, compounded / (t*12));"); System.out.println(); } } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
