السلام عليكم
ممكن تساعدوني في هذا البرنامج ومشكورين
اولا البرنامج يتكون من ثلاثة classes(MCircle ,MyPoints ,Test)
المطلوب من Class MyCircle حساب اذا كانت النقاط الموجودة فيTest class موجودة في حدود الدائرة ام لا.فإذا كانت مو في داخل الدائرة سوف تعيد القيمة true , اذا كانت النقاط في خارج الدائرة تعيد False
واليكم هذا جزء من الكود
public boolean MyCircle(MyPoints a){
//if(distance(a,x,y,radius)<= radius)
if(this.a<=radius)
return true;
else return false;
}المطلوب الثاني هو فحص اذا كانت الدائرة ممكن ان تحتوى ع دائرة مكتملة في داخلها ام لا.
//ix. A method named contains that return true if and only if the MyCircle completely contains a MyCircle passed as a parameter.
public boolean MyCircle(MyCircle b){
if (radius)
return true
else return false;
//x. A toString method.3) المطلوب الثالث حساب الاصغر مساحة بين النقطتين (هذا موجود في Test Class)
طبعا حاولت اعملة بهذا الشكل
package assignmentnumber3;
public class Test {
public static void main(String[]args){
//i.Create two MyPoints: one at 10,10, and the other at 20,20.
MyPoints p1 = new MyPoints(10,10);
MyPoints p2 = new MyPoints(20,20);
//ii.Create a MyCircle centered at one of your MyPoints from i, with radius of 10.
MyCircle c1 = new MyCircle(10,10,10);
//iii.Check and see if the other MyPoint from i, is contained in the MyCircle from
//step ii.
//Create an array of MyPoint and initialize them to the following values.
MyPoints[] points=new MyPoints[8];
points[0]= new MyPoints(-1,-1);
points[1]= new MyPoints(-1,3);
points[2]= new MyPoints(1,1);
points[3]= new MyPoints(2,0.5);
points[4]= new MyPoints(2,-1);
points[5]= new MyPoints(4,-0.5);
points[6]= new MyPoints(4,2);
points[7]= new MyPoints(3,3);
//MyPoints[][]c =new MyPoints[8][8];
//MyPoints [][] c={{-1,-1},{-1,3},{1,1},{2,0.5},{2,-1},{4,-0.5},{4,2},{3,3}};
int val1 = 0, val2 =1;
double shortestDistances = distance(points[val1][0],points[val1][1],points[val2][0],points[val2][1]);
for (int i = 0; i<points.length;i++){
for (int j = i+1; j<points.length;j++){
double distance = distance(points[0],points[1],points[j][0],points[j][1]);
if (shortestDistances> distance)
val1 = i;
val2= j;
shortestDistances = distance;
}//end for
}//end for
}//end main
System.out.println("The closest two points are ("+points[val1][0]+" , "points[val1][1]+" and "+points[val2][0]+" , "+
points[val2][1]);
} public static double distance(double x1,double y1,double,double x2,double x6);
return Math.sqrt(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)
}
}
package assignmentnumber3;
public class MyCircle {
private double x,y,radius;
//A constructor has three double parameters for x, y, and radius
public MyCircle(double x,double y, double radius){
this.x = x;
this.y = y;
this.radius= radius;
}//End MyCircle Constructoe
public MyCircle(MyPoints a,double radius){
this.x=a.getX();
this.y=a.getY();
this.radius =radius;
}
//iv. A no-arg constructor that creates a circle at (0,0) with radius 1. This
//constructor should call the constructor in iii.
public MyCircle(){
this(0,0,1);
}
//v. Three get methods for the x, y and radius properties.
public double getX(){return x;}
public double getY(){return y;}
public double getRadius(){ return radius;}
//vi. Three set methods for the x, y and radius properties.
public void setX(){this.x= x;}
public void setY(){this.y=y;}
public void setRadius(){this.radius= radius;}
//vii. A method named distance that returns the distance (a double) between this MyCircle and another MyCircle.
public double distance(double a,double x,double y,double radius){
return a =Math.sqrt(Math.pow(this.x-x,2)-Math.pow(this.y-y,2));
}
//viii. A method named contains that returns true if and only if the MyCircle contains a MyPoint passed as a parameter.
//passing MyPoints as a Parameter in MyCircle Class
public boolean MyCircle(MyPoints a){
//if(distance(a,x,y,radius)<= radius)
if(this.a<=radius)
return true;
else return false;
}
//ix. A method named contains that return true if and only if the MyCircle completely contains a MyCircle passed as a parameter.
public boolean MyCircle(MyCircle b){
if (radius)
return true
else return false;
//x. A toString method.
public String toString(){
//return "The distination between "+x+" and "+y +" is "+a;
return "Circle: at x ="+x+" y= "+y+" and radius "+radius ;
}
}//end class MyCircle