Hello, I'm trying to make a program that compares loans with interest rates from 5% - 8%, with an increment of 1/8.
The output should look something like:
Loan Amount: 10000
Number of Years: 5
Interest Rate Monthly Payment Total Payment
5% 188.71 11322.74
5.125% 189.28 11357.13
5.25% 189.85 11391.59
...
7.85% 202.16 12129.97
8.0% 202.76 12165.83
I believe that I have gotten the correct Interest Rate, I just can't get the correct numbers for Monthly and Total Payments (I've copied the formula exactly as it shows it in the book within another program). I also can't figure out how to make them adjust with the interest rate.
I'm new to loops so any kind of help will be appreciated,
Thanks
import java.util.Scanner; public class Exercise04_21 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Loan Amount: "); int loan = input.nextInt(); System.out.print("Number of Years: "); int years = input.nextInt(); System.out.printf("%10s %10s %10s\n", "Interest Rate", "Monthly Payment", "Total Payment"); double interest = 5.0; double monthlyPay = loan * (interest / 100) / (1 - 1 / Math.pow(1 + (interest / 100), years * 12)); double total = monthlyPay * 12 * years; while (interest <= 8.0) { System.out.printf("%10.2f %10.2f %10.2f%n", interest, monthlyPay, total); interest += 0.125; } } }