Colin
Colin

Reputation: 147

"error: cannot find symbol" in Java

I'm in my school's Compsci class, and one of our assignments was to use subroutines to have the user enter the radius of a circle, then return the circumference and the area of that circle. Here's the code I made to do that.

public class AreaAndCircumference {

    public static void main(String[] args){
        System.out.println("Enter the radius of a circle that you want to find the circumference and area of: ");
        double radius = TextIO.getlnDouble();
        double pi = 3.14159657;

        System.out.println("The circumference is" + circumference);
        System.out.println("The area is" + area);
    }

    public static double cirumference(double radius, double pi){
        return 2 * pi * radius;
    }

    public static double area(double radius, double pi){
        return pi * (radius * radius);
    }
}

I have three questions:

1) When I try to compile the code, I'm greeted by two errors:

 a. AreaAndCircumference.java:8: error: cannot find symbol
          System.out.println("The circumference is" + circumference);
    sumbol: variable circumference
    location: class AreaAndCircumference 


 b. AreaAndCircumference.java:9: error: cannot find symbol
          System.out.println("The area is" + area);
    sumbol: variable area
    location: class AreaAndCircumference 

Is this because it can't call the two variables? What do I do to fix this?

2) Here's sample code for a different program he provided us:

public class MetricConverter {

    public static void main(String[] args) {
        System.out.println("Welcome to the Metric Converter");
        System.out.print("Enter your height in inches: ");
        double heightInInches = TextIO.getlnDouble();

        System.out.println("Your height in cm is " + inchesToCm(heightInInches));
    }

    public static double inchesToCm(double inches) {
        return 2.54 * inches;
    }

}

What causes mine to not compile and this to compile?

3) I'm confused as to what you put in the parentheses after "public class static double area" or whatever else the class is. Do you put the variables you are referencing in there?

Upvotes: 0

Views: 564

Answers (1)

nobalG
nobalG

Reputation: 4620

Methods are called by having parenthesis and arguments in them

circumfererence and area are methods of class AreaAndCircumference and methods are called by having parenthesis and arguments in them .Hence,Change this

System.out.println("The circumference is" + circumference);
    System.out.println("The area is" + area);

to

System.out.println("The circumference is" + circumference(radius,pi));//you are missing paranethesis here
System.out.println("The area is" + area(radius,pi));//here to

Nice place to learn about methods and there arguments is here

Upvotes: 3

Related Questions