# New to object-oriented

• 03-26-2011, 06:08 PM
fluteattack
New to object-oriented
In class, we're moving from procedural programming to object-oriented. Here's the assignment I'm working on. I won't be surprised if all of this is wrong (I don't have a great handle on it yet), but I keep getting the same two errors: ".class expected" and "; expected".

Code:

```// ----------------------------------------------------------------- // This program prompts the user to enter a circle's radius, and // calculates and displays the circle's area, diameter and circumfrence. // ----------------------------------------------------------------- public class Circle {                private double radius;                        //radius         private final double PI = 3.14159;        //Pi                                                //****************************************************         //Accepts the radius of the circle as an argument                 public Circle(double newRadius)         {                 setRadius(double newRadius);                         }//end Constructor                                 //****************************************************         //A mutator method for the radius field                 public void setRadius(double newRadius)         {                 this.radius = radius;                         }//end setRadius                 //****************************************************         //An accessor method for the radius field                 public double getRadius()         {                 return this.radius;         }//end getRadius                 //****************************************************         //Returns the area of the circle, calculated as pi*R^2, R is the radius                 public double getArea()         {                 return PI*radius*radius;         }//end getArea                 //****************************************************         //Returns the diameter of the circle, calculated as 2R, R is the radius                 public double getDiameter()         {                 return 2*radius;         }//end getDiameter                 //****************************************************         //Returns the diameter of the circle, calculated as 2piR, R is the radius                 public double getCircumfrence()         {                 return 2*PI*radius;         }//end getCircumfrence                         } // end class Circle public class CircleRun {         public static void main(String args[])         {                 System.out.println("Please enter the radius of a circle: ");                 radius = in.nextDouble();                                 Circle cir = new Circle();                                 System.out.println("Area is: " + cir.getArea);                 System.out.println("Diameter is: " + cir.getDiameter);                 System.out.println("Circumfrence is: " + cir.getCircumfrence);         } }```
• 03-26-2011, 06:38 PM
SHE
Circle cir = new Circle(); --> why you do not insert the parameter !

Code:

```                 System.out.println("Please enter the radius of a circle: ");                 double [B][COLOR="YellowGreen"]radius [/COLOR][/B]= in.nextDouble();                                 Circle cir = new Circle([B][COLOR="YellowGreen"]radius [/COLOR][/B]);```
• 03-26-2011, 07:19 PM
fluteattack
Thanks.. the errors are on line 22 though
• 03-26-2011, 07:31 PM
Fubarable
Quote:

Originally Posted by fluteattack
Thanks.. the errors are on line 22 though

You might want to tell us which line is 22.
• 03-26-2011, 07:36 PM
fluteattack

In the first method
• 03-26-2011, 07:42 PM
Fubarable
Quote:

Originally Posted by fluteattack

In the first method

You're confusing calling a method with defining a method. When you create a method, you need to declare the variable types of the parameters, but when you call the same method, you don't declare the variable types, but rather you simply pass in the correct type of variable.

For example, you would define the method foo like so:

Code:

```// here we have to declare the parameter as int type public void foo(int value) {   System.out.println("value is: " + value); }```

But when you call foo, you don't declare the parameter type:

Code:

```int i = 10; // foo(int i);  // incorrect foo(i);  //correct```

Make sense?
• 03-28-2011, 01:43 PM
SHE
Code:

```public class Circle     {     private double redius ;     public final double PI = 3.14159;     public Circle(double redius) {         this.redius = redius;     }     public double getRedius() {         return redius;     }     public void setRedius(double redius) {         this.redius = redius;     }   public double getArea()     {         System.out.println("your Area is "+PI*redius*redius);         return PI*redius*redius;     }       public double getDimeter()     {         System.out.println("your Dimeter is "+2*redius);         return 2*redius;     }     public double getCircumfrence()     {         System.out.println("your Circumfrence is "+2*PI*redius);         return 2*PI*redius;     }     }```

Code:

```     public static void main(String[] args)     {         Scanner input = new Scanner(System.in);         System.out.println("Please Enter the redius to count the area");         double redius = input.nextDouble();         System.out.println("your redius is"+"["+redius+"]");         Circle crc1 = new Circle(redius);         crc1.getArea();         crc1.getDimeter();         crc1.getCircumfrence();             }```
try this one it work 100 %
I was wonder why you put PI as private ?