一个简单的Java 类,对象和方法的练习 急。。 在线等

来源:百度知道 编辑:UC知道 时间:2024/06/17 23:27:51
小妹学经济。。对计算机有点兴趣去 大一一不小心选到java。。。 这是最后一个作业 实在做不下去了。。 哪位师兄帮帮忙看一下 先谢过了

懒得看英文的话我在问题补充中稍微解释了一下。 翻译水平很烂。应该还是英文原题好理解吧

Rectangle
For this question you must write a Java program which has a class and some objects. Your task is to write a class called Rectangle which represents and permits manipulation of rectangles. The rectangles will exist in a standard Cartesian co-ordinate system with doubles used for the x and y coordinate values.You should use "Getter" and "Setter" methods to maintain the integrity of the objects that are created.
You should have at least two formats for specifying rectangles in the constructors - as two sets of coordinates (say the bottom-left and the top-right) for a general rectangle, and one for a square with one coordinate position (say bottom-left) and one double representing the width and height of the square. In addition you should have a default constructor that creates a rectangle with unit width and height pos

大早上浪费个半天给你写这个....诶 还没洗脸呢...
public class Rectangle {

public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangle rec=new Rectangle(1.0,1.0,2.0,2.0);
System.out.println(rec.toString());
Rectangle rec2=new Rectangle(1.0,1.0,1.0);
System.out.println(rec.largerArea(rec2));
System.out.println(rec2.isSquare());
Rectangle rec3=rec2.copy();
System.out.println(rec.intersect(rec2));
rec3.print();
System.out.println(rec.diagonal());
}
private double bottomLeftX; //左下角坐标
private double bottomLeftY;
private double topRightX; //右上坐标
private double topRightY;
private double height;
private double width;

public Rectangle(double blx, double bly, double trx, double topry) {
this.bottomLeftX = blx;
this.bottomLeftY = bly;
this.topRightX = trx;
this.topRightY = topry;
this.width = topr