File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 24199

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!

I agree. Here's the link:
subject: Newbie Question : cannot resolve symbol : variable
It's not a secret anymore!