Here is the problem I have to answer: (Compare loans with various interest rates) Write a program that lets the user enter the loan amount and loan period in number of years and displays the monthly and total payments for each interest rate starting from 5% to 8%, with an increment of 1/8.
import java.util.Scanner; // Scanner is in java.util
public class FinancialApp {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // Scanner object
System.out.print("Enter loan amount: "); // input value for loan
double loanAmount = input.nextDouble();
System.out.print("Enter number of years as an integer: ");
int years = input.nextInt();
System.out.println("Intrest Rate" + "\t" + "Monthly Payment" + "\t" + "Total Payment");
for(double i = 5.000; i <= 8.000; i += 0.125){
double monthlyIntrest = i / 1200;
double monthlyPay = loanAmount * monthlyIntrest / (1 - 1 / Math.pow(1 + monthlyIntrest, years * 12));
double totalPay = monthlyPay * years * 12;
System.out.println(i + "%" + "\t" + monthlyPay + "\t" + totalPay);
}
}
}