jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Newbie Question : cannot resolve symbol : variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Newbie Question : cannot resolve symbol : variable" Watch "Newbie Question : cannot resolve symbol : variable" New topic

Newbie Question : cannot resolve symbol : variable

Michael Lukatchik

Joined: Jul 03, 2005
Posts: 2
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!


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();

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);

private static double calculateFutureValue(double monthlyPayment, double monthlyInterestRate, int months)
int i = 1;
double futureValue = 0;

while (i <= months)
futureValue = (futureValue + monthlyPayment) * (interestRate + 1);
return futureValue;

Michael J. Lukatchik<br />Web App. Solution Dept.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

Hi Michael,

Welcome to JavaRanch!

The variable "interestRate" is declared in main(); it's not visible inside other methods. You can pass it as a parameter to calculateFutureValue(), the same way you've passed the other parameters.

[Jess in Action][AskingGoodQuestions]
Michael Lukatchik

Joined: Jul 03, 2005
Posts: 2
Hello Ernest Friedman-Hill,

I see, it was all about the scope of the variable...Thanks a ton!

Consider Paul's rocket mass heater.
subject: Newbie Question : cannot resolve symbol : variable
Similar Threads
NullPointerException thrown in JOptionPane
static method data validation in a dialog box app
Format the output
Help with errors again
One error in code..not understanding what it tells me. Code works it is on line 55.