Here is the question from the text: "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."
I cannot seem to figure out how to start at 5% and stop at 8% with a 1/8 increment increase.
Here is what I have so far:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter loan amount: ");
double loanAmount = input.nextDouble();
System.out.print("Enter number of years: ");
int numOfYears = input.nextInt();
double annualInterestRate = 5;
double monthlyInterestRate = annualInterestRate/1200;
double monthlyPayment = loanAmount * monthlyInterestRate /
(1 - (Math.pow(1 / (1 + monthlyInterestRate), numOfYears * 12)));
double totalPayment = monthlyPayment * 12 *numOfYears;
System.out.println("Loan Amount: " + loanAmount);
System.out.println("Number of Years: " + numOfYears);
System.out.println();
System.out.println("Interest Rate \t Monthly Payment \t Total Payment");
double i = 5.0;
while (i <= 8.0){
i = i + 0.125;
i++;
monthlyPayment = (int)(monthlyPayment * 100) / 100.0 ;
totalPayment = (int)(totalPayment * 100) / 100.0;
System.out.println(i + "\t\t" + monthlyPayment + "\t\t" + totalPayment );
}
}
}
The output of this code is this:
Enter loan amount: 10000
Enter number of years: 5
Loan Amount: 10000.0
Number of Years: 5
Interest Rate Monthly Payment Total Payment
6.125 188.71 11322.74
7.25 188.71 11322.74
8.375 188.71 11322.74
As you can see the interest rates are not correct nor are the monthly payments or total payments. Any help would be very much appreciated as I have been staring at this for 4+ hours

New Topic/Question
Reply
MultiQuote





|