# help guys.. could you tell me what am i doing wrong?

• February 12th, 2011, 01:26 PM
gonfreecks
help guys.. could you tell me what am i doing wrong?
i am designing this my circle class

i. It should contain three private doubles for x, y and radius.
ii. A constructor that accepts three double parameters for x, y, and radius.
iii. A constructor that accepts a MyPoint and a radius. This constructor should
call the constructor in ii.
iv. A no-arg constructor that creates a circle at (0,0) with radius 1. This
constructor should call the constructor in iii.
v. Three get methods for the x, y and radius properties.
vi. Three set methods for the x, y and radius properties.
vii. A method named distance that returns the distance (a double) between this
MyCircle and another MyCircle.
viii. A method named contains that returns true if and only if the MyCircle
contains a MyPoint passed as a parameter.
ix. A method named contains that return true if and only if the MyCircle
completely contains a MyCircle passed as a parameter.
x. A toString method.
xi. A static void main method for testing the MyCircle class

so far i have this code

public class MyCircle {
private double x;
private double y;

public MyCircle(double x, double y, double radius){
this.x = x;
this.y = y;
}

this.x = point.getX();
this.y = point.getY();
}

public MyCircle(){
this.x = 0;
this.y = 0;
}

public double getX(){
return x;
}

public double getY(){
return y;
}

}

public void setX(double x){
this.x = x;
}

public void setY(double y){
this.y = y;
}

}

public double distance(MyCircle other){
double result = 0;

double tmpX = this.x - other.x;
double tmpY = this.y - other.y;

result = Math.sqrt((tmpX*tmpX)*(tmpY*tmpY));

return result;

}

public boolean contains(MyPoint o){
boolean tmp;
double result;

double tmpX = this.x - o.getX();
double tmpY = this.y - o.getY();
System.out.println(tmpX);
System.out.println(o.getX() + " + " + this.x);
result = Math.sqrt((tmpX*tmpX)*(tmpY*tmpY));
System.out.println(result);
tmp = true;
else
tmp = false;
return tmp;

}

public String toString(){
return "Point x = " + this.x + "\nPoint y = " +this.y
}

public static void main(String [] args){

MyPoint p = new MyPoint(1,4);
MyCircle c = new MyCircle(p,3);
System.out.println(c);
MyCircle x = new MyCircle();
boolean tmp = x.contains(p);
System.out.println(tmp);

}
}

and could someone explain the rule ix, thx god bless
• February 12th, 2011, 01:59 PM
tiagoufrj
Re: help guys.. could you tell me what am i doing wrong?
If A and B are circles. B is contained in A if and only if the distance between A and B plus the radius of B is smaller than radius of A.

make sense? I think so.