Java Code/Program - Loan Calculator/Loan Payments
by matt392 in Circuits > Software
45 Views, 2 Favorites, 0 Comments
Java Code/Program - Loan Calculator/Loan Payments
Java code/program for computing loan payments.With comments to make it easier to follow.Formula is attached as a PDF and below.Monthly Payment = Loan Amount x Monthly Interest Rate _____________________________________ 1 1 - ____________________________________________ (Number of Years x 12) (1 + Monthly Interest Rate)public class ComputingLoanPayments { public static void main(String[] args) { Scanner keyboardInput = new Scanner(System.in); double loanAmount, annualInterestRate, monthlyInterestRate, firstPartOfFormula, bottomPartOfFormula, topPartOfFormula, monthlyPayment; int numberOfYears, numberOfMonths; // Enter the amount to be loaned System.out.println("Enter the Loan Amount: "); loanAmount = keyboardInput.nextDouble(); // Enter the annual interest System.out.println("Enter the Annual Interest Rate: "); annualInterestRate = keyboardInput.nextDouble(); // Enter the years to pay back System.out.println("Enter the number of years that you would like to pay the loan back over: "); numberOfYears = keyboardInput.nextInt(); // First convert the Annual Interest Rate to the Monthly Interest Rate // Formula is: Annual Interest Rate/Number of Months // Before we do this, we need to calculate the Number of Months numberOfMonths = numberOfYears * 12; System.out.println("The number of months is: " + numberOfMonths); // Now we will convert to the Annual Interest Rate // Don't forget to divide the Annual Interest Rate by 100! monthlyInterestRate = (annualInterestRate/100)/numberOfMonths; System.out.println("The monthly interest rate is: " + monthlyInterestRate); // Now we will calculate (1+monthlyInterestRate) ^ (numberOfYears * 12) firstPartOfFormula = Math.pow((1+monthlyInterestRate),(numberOfYears*12) ); System.out.println("First part of formula is: " + firstPartOfFormula); // Now we will finish the bottom portion of the formula bottomPartOfFormula =(1-(1/firstPartOfFormula)); System.out.println("The whole bottom part of the formula is: " + bottomPartOfFormula); // Now we will calculate the top part of the formula which is: // loanAmount * monthlyInterestRate topPartOfFormula = loanAmount * monthlyInterestRate; System.out.println("The top part of the formula is: " + topPartOfFormula); // Finally we will get to the main answer monthlyPayment = topPartOfFormula/bottomPartOfFormula; System.out.printf("The monthly payment is: $%.2f", monthlyPayment); } // end main method } // end class
Supplies
- Eclipse IDE
- Java