Error in method class.

I am trying to write a method that accesses a class called circle where the user inputs the radius of a circle and the program prints the area, radius and circumference.

My class is as follows.

public class Circle

{

private double Radius;

private double PI = 3.14159;

public void setRadius(double rad)

{

Radius = rad;

}

public void setPI(double pi)

{

PI = pi;

}

public double getRadius()

{

return Radius;

}

public double getPI()

{

return PI;

}

public double getArea()

{

return PI * Radius * Radius;

}

public double getDiameter()

{

return Radius * Radius;

}

public double getCircumferance()

{

return 2 * PI * Radius;

}

}
I am not having any areas when compiling the class.

The method is as follows.

//IS 115
//DED01
//Method for Circle class
//Larry Piatt

public class CircleStats

{

public static void main(String[] args)

{

double number;

Scanner keyboard = new Scanner(System.in);

Circle Radius = new Circle();
Circle Area = new Circle();
Circle Diameter = new Circle();
Circle Circumference = new Circle();


System.out.println("What is the radius of the circle? ");
number = keyboard.nextdouble();
number.setRadius(number);

System.out.println("The area of the circle is "
+ Area);

System.out.println("The diamter of the circle is "
+ Diameter);

System.out.println("The circumference of the circle is "
+ Circumference);

}

}

The errors that I am seeing are as follows

CircleStats.java:27: cannot find symbol
symbol : method nextdouble()
location: class java.util.Scanner
number = keyboard.nextdouble();
^
CircleStats.java:28: double cannot be dereferenced
number.setRadius(number);
^
2 errors

This is my first attempt at writting a method that calls a class. I am not understanding it very well yet. Any assistance would be greatly appreciated.

Comments

  • : I am trying to write a method that accesses a class called circle
    : where the user inputs the radius of a circle and the program prints
    : the area, radius and circumference.
    :
    : My class is as follows.
    :
    : public class Circle
    :
    : {
    :
    : private double Radius;
    :
    : private double PI = 3.14159;
    :
    : public void setRadius(double rad)
    :
    : {
    :
    : Radius = rad;
    :
    : }
    :
    : public void setPI(double pi)
    :
    : {
    :
    : PI = pi;
    :
    : }
    :
    : public double getRadius()
    :
    : {
    :
    : return Radius;
    :
    : }
    :
    : public double getPI()
    :
    : {
    :
    : return PI;
    :
    : }
    :
    : public double getArea()
    :
    : {
    :
    : return PI * Radius * Radius;
    :
    : }
    :
    : public double getDiameter()
    :
    : {
    :
    : return Radius * Radius;
    :
    : }
    :
    : public double getCircumferance()
    :
    : {
    :
    : return 2 * PI * Radius;
    :
    : }
    :
    : }
    : I am not having any areas when compiling the class.
    :
    : The method is as follows.
    :
    : //IS 115
    : //DED01
    : //Method for Circle class
    : //Larry Piatt
    :
    : public class CircleStats
    :
    : {
    :
    : public static void main(String[] args)
    :
    : {
    :
    : double number;
    :
    : Scanner keyboard = new Scanner(System.in);
    :
    : Circle Radius = new Circle();
    : Circle Area = new Circle();
    : Circle Diameter = new Circle();
    : Circle Circumference = new Circle();
    :
    :
    : System.out.println("What is the radius of the circle? ");
    : number = keyboard.nextdouble();
    : number.setRadius(number);
    :
    : System.out.println("The area of the circle is "
    : + Area);
    :
    : System.out.println("The diamter of the circle is "
    : + Diameter);
    :
    : System.out.println("The circumference of the circle is "
    : + Circumference);
    :
    : }
    :
    : }
    :
    : The errors that I am seeing are as follows
    :
    : CircleStats.java:27: cannot find symbol
    : symbol : method nextdouble()
    : location: class java.util.Scanner
    : number = keyboard.nextdouble();
    : ^
    : CircleStats.java:28: double cannot be dereferenced
    : number.setRadius(number);
    : ^
    : 2 errors
    :
    : This is my first attempt at writting a method that calls a class. I
    : am not understanding it very well yet. Any assistance would be
    : greatly appreciated.
    :
    Java is case-sensitive. Thus to the compiler:
    [code]
    keyboard.next[b][red]d[/red][/b]ouble();
    [/code]
    and
    [code]
    keyboard.next[b][red]D[/red][/b]ouble();
    [/code]
    are two completely different things. The error "cannot find symbol" is usually the result of either a typo or a casting-error.
    Your second error is a result of using the wrong instance at the wrong time. You want to set the radius of a circle, not the number entered by the user. The "class" double doesn't have any methods, because it isn't an Object.

  • : :
    : Java is case-sensitive. Thus to the compiler:
    : [code]:
    : keyboard.next[b][red]d[/red][/b]ouble();
    : [/code]:
    : and
    : [code]:
    : keyboard.next[b][red]D[/red][/b]ouble();
    : [/code]:
    : are two completely different things. The error "cannot find symbol"
    : is usually the result of either a typo or a casting-error.
    : Your second error is a result of using the wrong instance at the
    : wrong time. You want to set the radius of a circle, not the number
    : entered by the user. The "class" double doesn't have any methods,
    : because it isn't an Object.



    Thank you for the assist. I had found the case problem. And was stumbling around trying to work out the second issue. I am still having a problem though. I changed it from setting a double to setting a method and all the errors went away. But now I am getting bad results. I figure it is either one of 2 things.

    First, I have the calls messed up so it is accessing the data in the wrong order.
    or
    Second, I have the wrong primitive data type. I don't think that is the issue but it might be. Any suggestions on how to trouble shoot it would be appreciated:-) Thanks.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories