Help with Cannot Find Symbol Variable errors
Hi - I am in a beginning Java class and cannot figure out this assignment. We were given steps to do and I thought I had done them right but what I didn't expect were a whole bunch of 'cannot find symbol - variable XXX' for all of my variables (tuition, fees, rate, etc) which were declared.
Could someone take a look and help? I have to turn this in at noon....
Thanks in advance!!!
Code Java:
import java.io.*;
import java.text.DecimalFormat;
public class Tuition
{
public static void main(String[] args) throws IOException
{
//Declaring Variables
int hours;
double fees, rate, tuition;
BufferedReader myIn= new BufferedReader(new InputStreamReader(System.in));
// Call Methods
displayWelcome();
hours = getHours();
rate = getRate(hours);
tuition = calcTuition(hours, rate);
fees = calcFees(tuition);
displayTotal(tuition + fees);
}
public static void displayWelcome()
{
System.out.println("\tWelcome to the Tuition and Fees Estimator");
}
public static int getHours()
{
//declare method variables
String strHours;
int hours = 0;
try
{
System.out.print("\t\tEnter the total number of hours enrolled: ");
strHours = myIn.readLine();
hours = Integer.parseInt(strHours);
}
catch(NumberFormatException e)
{
System.out.println("An error has occurred. You must enter an integer. " +
e.getMessage());
//message prints with Java-generated data
}
return hours;
}
public static double getRate(int hours)
{
if (hours > 15)
{
rate = 44.50;
}
else
{
rate = 50.00;
}
return rate;
}
public static double calcTuition(int hours, double rate)
{
tuition = hours * rate;
return tuition;
}
public static double calcFees(double tuition)
{
fees = tuition * .08;
return fees;
}
public static void displayTotal(double total)
{
DecimalFormat twoDigits = new DecimalFormat("$#,000.00");
System.out.println("\t\tYour total tuition and fees are " + twoDigits.format(tuition + fees) + ".");
System.out.println("\t\tThank you!");
}
}
Re: Help with Cannot Find Symbol Variable errors
The problem you are having is due to the scope you declared your variables in.
Since you declared them in the main method, they are method variables (only exist in the scope of the main method). If you want to use them in all of your static methods, you need to declare them as static members of the Tuition class
Re: Help with Cannot Find Symbol Variable errors
Thanks so much! Any hint on how to go about doing that? (I'm just a java newbie!) :o
Re: Help with Cannot Find Symbol Variable errors