1. Member
Join Date
Mar 2011
Posts
4
Rep Power
0

## 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".

Java 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 final double PI = 3.14159;	//Pi

//****************************************************
//Accepts the radius of the circle as an argument

{

}//end Constructor

//****************************************************
//A mutator method for the radius field

{

//****************************************************
//An accessor method for the radius field

{

//****************************************************
//Returns the area of the circle, calculated as pi*R^2, R is the radius

public double getArea()
{
}//end getArea

//****************************************************
//Returns the diameter of the circle, calculated as 2R, R is the radius

public double getDiameter()
{
}//end getDiameter

//****************************************************
//Returns the diameter of the circle, calculated as 2piR, R is the radius

public double getCircumfrence()
{
}//end getCircumfrence

} // end class Circle

public class CircleRun
{
public static void main(String args[])
{

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);
}
}```

2. Member
Join Date
Mar 2011
Posts
27
Rep Power
0
Circle cir = new Circle(); --> why you do not insert the parameter !

Java Code:
```		System.out.println("Please enter the radius of a circle: ");

Circle cir = new Circle([B][COLOR="YellowGreen"]radius [/COLOR][/B]);```
Last edited by SHE; 03-26-2011 at 07:54 PM.

3. Member
Join Date
Mar 2011
Posts
4
Rep Power
0
Thanks.. the errors are on line 22 though

4. Originally Posted by fluteattack
Thanks.. the errors are on line 22 though
You might want to tell us which line is 22.

5. Member
Join Date
Mar 2011
Posts
4
Rep Power
0

In the first method

6. 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:

Java 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:

Java Code:
```int i = 10;

// foo(int i);  // incorrect

foo(i);  //correct```

Make sense?

7. Member
Join Date
Mar 2011
Posts
27
Rep Power
0
Java 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()
{
return PI*redius*redius;
}

public double getDimeter()
{
return 2*redius;
}

public double getCircumfrence()
{
return 2*PI*redius;
}

}```

Java 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();
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 ?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•