Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Help with Cannot Find Symbol Variable errors

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!!!

    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!");
    	}
    }


  2. #2
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default 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

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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!)

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with Cannot Find Symbol Variable errors

    Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

Similar Threads

  1. cannot find symbol Error
    By bananasplitkids in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 9th, 2010, 02:36 AM
  2. Why the compiler can not find the symbol?
    By AlicNewbie in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 16th, 2010, 08:16 PM
  3. cannot find symbol - method
    By kyuss in forum Object Oriented Programming
    Replies: 2
    Last Post: December 7th, 2009, 01:01 PM
  4. cannot find symbol variable radius?
    By noobish in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 4th, 2009, 10:29 AM
  5. Replies: 5
    Last Post: September 19th, 2009, 06:48 AM