我有下面的類來寫: 寫了一個名爲XYRectangle_LastName,其中名字被替換爲您的姓氏類。該XYRectangle_LastName類應具有以下字段:寫一個XYRectangle類在Java中
的名爲TopLeft的XYPoint。這存儲了Rectangle的頂部角落的位置。
一個名爲Length的雙。這存儲矩形的長度。
一個名爲Width的雙。這存儲矩形的寬度。
的XYRectangle類應該有以下方法:
一個無參數的構造函數,隨機地確定的矩形的左上角。 x和y的值應該在-10和10之間。此外,它爲值爲5和10之間的矩形選擇隨機寬度和長度。
3參數構造函數,它爲XY左上角,長度和寬度。
爲一個Get方法的長度,寬度,左上,topRight,BOTTOMLEFT和bottomRight
對於長度,寬度的一組方法,和左上
名爲isInside的布爾方法,其採用的Xypoint,並且確定是否它在這個矩形裏面。
一個名爲reflectX的方法,它返回一個已反映在x軸上的矩形。
一種名爲reflectY的方法,用於返回已在y軸上反射的矩形。
這是我到目前爲止的代碼:
public class XYRectangle {
private XYPoint topLeft;
private double length;
private double width;
public XYRectangle() {
Random rnd = new Random();
int x = (rnd.nextInt(21) - 10);
int y = (rnd.nextInt(21) -10);
XYPoint topLeft = new XYPoint(x, y);
int width = (rnd.nextInt(5) + 5);
int height = (rnd.nextInt(5) + 5);
}
public XYRectangle(XYPoint topLeft, double length, double width) {
this.topLeft = topLeft;
this.length = length;
this.width = width;
}
public double getLength() { return this.length; }
public void setLength(double length) { this.length = length; }
public double getWidth() { return this.width; }
public void setWidth(double width) { this.width = width; }
public XYPoint getTopLeft() { return this.topLeft; }
public void setTopLeft(XYPoint topLeft) { this.topLeft = topLeft; }
我在與topRight,BOTTOMLEFT和bottomRight麻煩了方法和反映方法
。我甚至不確定到目前爲止我寫的代碼是否寫入。任何人都可以幫助並告訴我如何繼續,如果我一直在做錯什麼?
嗯,這聽起來很瘋狂我知道,但是...那麼你如何試着編譯你的代碼並逐步查看它是否有效? – scottb
那種愚蠢的我不去嘗試明顯的。謝謝! – ch1maera