该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
//初学者,当练习做
// Test.java
//点
class Spot
{
private int x,y;
Spot()
{
x = 0;
y = 0;
}
Spot(int x0,int y0)
{
x = x0;
y = y0;
}
public int deltaX(Spot s)
{
return (this.x - s.x);
}
public int deltaY(Spot s)
{
return (this.y - s.y);
}
}
//矩形
//upLeft表示矩形左上角的点,downRight表示矩形右下角的点
//坐标系是数学里的,x正方向向右,y正方向向上
class MyRectangle
{
private Spot upLeft,downRight;
MyRectangle()
{
upLeft = new Spot();
downRight = new Spot();
}
MyRectangle(int x1,int y1,int x2,int y2)
{
upLeft = new Spot(x1,y1);
downRight = new Spot(x2,y2);
}
public int getHeight()
{
return upLeft.deltaY(downRight);
}
public int getWidth()
{
return downRight.deltaX(upLeft);
}
}
//主类,测试
public class Test
{
public static void main(String[] args)
{
System.out.println("^_^");
MyRectangle myRec = new MyRectangle(1,5,4,1);
System.out.println("width:" + myRec.getWidth());
System.out.println("height:" + myRec.getHeight());
}
}