### Thread: Circle class help needed

Page 2 of 2 First 12
1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
17
Rep Power
0
I get the point you are making, but based on the code I have written, it seems like I am not using the move method at all.

Code:
```public class Circle {

//Fields of the class.
public double xCoord;
public double yCoord;
public int x;
public int y;

//Main method and the object of the class.
public static void main(String[] args) {
Circle cir= new Circle();
cir.printAttributes();
}

//First constructor; sets default values.
public Circle(){

this.xCoord=10;
this.yCoord=10;
}

//The second constructor takes three doubles as parameters corresponding to the X and Y coordinates & the radius.
public Circle(double x,double y,double r){
xCoord=x;
yCoord=y;

}

//The ternary conditional operator resets the value to the specified maximum radius.
double maxR=100.00;

}

}

//Returns X-Coordinate.
public double getxCoord() {
return xCoord;
}
//Returns Y-Coordinate.
public double getyCoord() {
return yCoord;
}
//Returns X value.
public int getX() {
return x;
}
//Returns Y value.
public int getY() {
return y;
}

//Returns the circumference of the circle.
public double circumference(){
}

//Returns the area of the circle.
public double area(){
}

//Prints the coordinates, the radius, the circumference, and the area.
public void printAttributes(){
System.out.println("**Java Circle Class**");
System.out.println("");
System.out.println("Area: "+area()+"\nCircumference: "+circumference()+"\nRadius: "+getRadius(300)+"\nX-Coordinate: "+xCoord+"\nY-Coordinate: "+yCoord+"\nPoints fall inside the circle? "+isInside(x, y));
}

//Returns true if a point represented in the parameters falls inside the circle, false otherwise.
public boolean isInside(double x, double y) {
double distance;
x=x-xCoord;
y=y-yCoord;
distance= Math.sqrt((x*x)+(y*y));
return true;
else
return false;
}

//Moves the origin by a specified amount.
public void move(int x, int y) {
x=10;
y=10;

}```
2. I am not using the move method at all.
That's what it looks like to me also.

What does your assignment say about using the methods in the class?

For testing you should add code to the main() method that calls the move() method and then prints out the circle's data again after it was moved so you could check if move() did what you wanted.
Last edited by NormR; July 9th, 2013 at 08:11 PM.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
17
Rep Power
0
Write a class called Circle which has two constructors. The first constructor (default constructor) does not take any parameter and supplies default values for the coordinates and the radius. The second constructor takes three doubles as parameters corresponding to the X and Y coordinates and the radius. The class must include these methods:

public double circumference() – returns the circumference of the circle.
public double area() – returns the area of the circle.
public void setRadius(double r) – is called in the constructor and checks the radius against a maximum. If the radius is greater than the maximum, setRadius resets it to the maximum (using the ternary conditional operator). You may set your own maximum value.
public void printAttributes() – prints the coordinates, the radius, the circumference, and the area.
public boolean isInside(double x, double y) – return true if a point represented in the parameters falls inside the circle, false otherwise.
public void move(int x, int y) – moves the origin by a specified amount.
4. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2012
Posts
103
Rep Power
3
It might just be an exercise for you to code it up. It doesn't look like its required for any internal functions. Your second assignment might have you expand on the circle program and use the move method.
5. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2013
Posts
17
Rep Power
0
thanks guys.
Page 2 of 2 First 12