Java Loan Calculator. Wrote code for a loan calculator but mypayments seem to be calculating too high.
Fantastic news! We've Found the answer you've been seeking!
Question:
Java Loan Calculator. Wrote code for a loan calculator but mypayments seem to be calculating too high. ive attached theinstructions given and the code I wrote. wondering if my monthlypayment and total payment formulas are written correctly? any helpwould be appreciated.
My Code:
public class Assignment2 { public static void main(String[] args){ //Creating the Scanner object Scanner input = new Scanner(System.in); //have user input number of years, rate of interest and loan amount System.out.print("Enter loan term in years: "); int numberOfYears = input.nextInt(); System.out.print("Enter interest rate: "); double monthlyInterestRate = input.nextDouble(); System.out.print("Enter loan amount: "); double loanAmount = input.nextDouble(); //calculate monthly payments double monthlyPayment = ((loanAmount * monthlyInterestRate) / (1 - (1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 12)))); //display monthly payment details to console System.out.print("Your monthly payment is: "); System.out.println(monthlyPayment); //calculate total payment double totalPayment = (monthlyPayment * numberOfYears * 12); //display monthly total details to console System.out.print("Your total payment is: "); System.out.println(totalPayment); }}
Related Book For
Principles of Corporate Finance
ISBN: 978-1260013900
13th edition
Authors: Richard Brealey, Stewart Myers, Franklin Allen
Posted Date: