Hello all,
I've been working on an introductory
Java program and encountered the following error:
cannot resolve symbol
symbol : variable interestRate
location: class FutureValueApp
futureValue = (futureValue + monthlyPayment) * (interestRate + 1); The compiler does not like the interestRate variable in this statement.
In my research, I verified that my environment variables pointed to my \bin directory and that I configured the CLASSPATH variable, which was set with a value of a period (.)
I'm posting the code that I've worked with so far. If you can spot the error here, or if you place it into your editor and run it, please give me some feedback as to how I can troubleshoot this problem. Thanks in advance!
Mike
---------------------------------------------------------
import javax.swing.*;
import java.text.*;
public class FutureValueApp
{
public static void main(
String[] args)
{
String choice = "";
while (!(choice.equalsIgnoreCase("X")))
{
String paymentString = JOptionPane.showInputDialog
("Enter monthly payment: ");
double monthlyPayment = Double.parseDouble(paymentString);
String rateString = JOptionPane.showInputDialog
("Enter yearly interest rate: ");
double interestRate = Double.parseDouble(rateString);
double monthlyInterestRate = interestRate/12/100;
String yearString = JOptionPane.showInputDialog
("Enter number of years: ");
int years = Integer.parseInt(yearString);
int months = years * 12;
//Call the static method that contains the input of these three fields
double futureValue = calculateFutureValue(monthlyPayment, monthlyInterestRate, months);
NumberFormat currency = NumberFormat.getCurrencyInstance();
NumberFormat percent = NumberFormat.getPercentInstance();
percent.setMinimumFractionDigits(2);
String message =
"Monthly payment: " + currency.format(monthlyPayment) + "\n"
+ "Yearly interest rate: " + percent.format(interestRate/100) + "\n"
+ "Number of years: " + years + "\n"
+ "Future value: " + currency.format(futureValue) + "\n\n"
+ "To continue, press Enter.\n"
+ "To exit, enter 'X'";
choice = JOptionPane.showInputDialog(null, message, "Future Value", JOptionPane.PLAIN_MESSAGE);
}
System.exit(0);
}
private static double calculateFutureValue(double monthlyPayment, double monthlyInterestRate, int months)
{
int i = 1;
double futureValue = 0;
while (i <= months)
{
futureValue = (futureValue + monthlyPayment) * (interestRate + 1);
i++;
}
return futureValue;
}
}