我環顧四周,看起來很像它,但它們總是使用變量X1,X2和Y1 Y2,並且im不允許要做到這一點。 對於分配我有2班,讓我們調用這些A和B從點對象獲取值,用作Java中的圓對象的中心
Class A
//Punt (x,y)
Punt mp1 = new Punt(1.0, 2.0)
Punt mp2 = new Punt(3.0, 4.0)
//Circle(center, radius)
Circle c1 = new Circle(mp1, 1.0)
Circle c2 = new Circle(mp1, 1.0)
現在,在B類,我需要看是否圓重疊,所以我想看看距離beweteen中心點< radius1的+ radius2。我必須公開布爾重疊(Circle that)
Class B
private Punt center
private double radius
public Circle(Punt mp, double ra)
center = mp
radius = ra
public boolean overlap(Circle that)
//here I would need to find the distance between the distance of the centers with Pythagorean theorem
double sumRadius = this.radius + that.radius //this one works
if (distCenter <= sumRadius)
return true
else
return false;
我試過比我想象的更多,但沒有任何工作,任何提示?
林不允許只是讓X1和X2,開創A級等
編輯您的帖子更清晰......而使用Java語法 – 2014-09-21 14:08:26