Hi guys. I am getting the error: LoanProgram.java:17: variable payment might not have been initialized
payment = getPayment (amount, rate, years, months, payment);
I am stumped, and the lab is due tomorrow. If anyone could help me out I would greatly appreciate it. :)
I'll put an asterisk on the line with the error.
import java.util.Scanner;
import java.text.DecimalFormat;
public class LoanProgram
{
static Scanner input = new Scanner (System.in);
public static void main (String [] args)
{
int years, months;
double amount, rate, payment;
amount = getAmount ();
rate = getRate ();
years = getYears ();
months = years * 12;
*payment = getPayment (amount, rate, years, months, payment);
System.out.println (payment);
}
public static double getAmount ()
{
System.out.print ("Enter the amount you are borrowing: ");
double amount = input.nextDouble ();
if (amount < 0 || amount > 100000)
{
System.out.print ("invalid. Enter amount: ");
amount = input.nextDouble ();
}
return amount;
}
public static double getRate ()
{
System.out.print ("Enter the annual interest rate as a percent: ");
double rate = input.nextDouble ();
if (rate < 0)
{
System.out.print ("You can't have a negative rate. Enter amount: ");
rate = input.nextDouble ();
}
return rate;
}
public static int getYears ()
{
System.out.print ("Enter the length of the loan in years: ");
int years = input.nextInt ();
if (years < 1)
{
System.out.print ("The minimum amount of years is 1. Enter amount: ");
years = input.nextInt ();
}
return years;
}
public static double getPayment (double amount, double rate, int years, int months, double payment)
{
months = years * 12;
payment = amount * rate * (Math.pow(rate + 1, months)/((Math.pow(rate + 1, months)-1)));
return payment;
}
}