Ok so I am working on a program that involves loans and gives information to the user about loans from what the user inputs.
The purpose of this program I am writing is for the user to be asked to input a loan amount and the number of years that they have to pay it off. Once the user has given this information, the program will take the loan amount and number of years and tell the user the annual interest rate, monthly payment and the total amount. ALSO, if the user enters a loan amount of -1, the program is supposed to terminate.
Below is my code thus far:
package Loans;
import java.util.Scanner;
public class Loans {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
double monthlyInterestRate;
double annualInterestRate;
double monthlyPayment;
double total;
double numberOfYears;
double loanAmount;
System.out.println("This program will compute the monthly payments and total payments for a loan amount on interest rates starting at 5%, incrementing by 1/8th percent up to 8%.");
//Formula to Calculate Monthly Interest Rate:
monthlyInterestRate = (annualInterestRate/1200);
//Formula to Calculate Monthly Payment:
monthlyPayment = (loanAmount*monthlyInterestRate);
//Formula To Calculate Annual Interest Rate:
annualInterestRate = (1-(Math.pow(1/(1 + monthlyInterestRate), numberOfYears * 12)));
//Formula To Calculate The Total Payment:
total = (monthlyPayment*numberOfYears*12);
while(true)
{
System.out.println("Please enter in the loan amount.");
double loanAmount = input.nextDouble();
System.out.println("Please enter in the number of years.");
double numberOfYears = input.nextDouble();
System.out.println("Interest Rate: " + annualInterestRate);
System.out.println("Monthly Payment: " + monthlyPayment);
System.out.println("Total Payment: " + total);
}
}
}
This does not compile and I'm not sure why. (Again, I'm a beginner)
The errors I am receiving are on the line that reads "double loanAmount = input.nextDouble();" AND the line that reads "double numberOfYears = input.nextDouble();".
The error for the first line says, "Duplicate local variable loanAmount".
The error for the second line says, "Multiple markers at this line - Line breakpoint:Loans [line: 39] - main(String[]) - Duplicate local variable numberOfYears"
Any feedback is appreciated.