public class Block extends Shape { //Data private Point d1; //top left corner private Point d2; //down right corner //Constructors public Block(double x1,double y1,double x2,double y2) throws RuntimeException { if(x1==x2 || y1==y2) throw new RuntimeException("Invalid data!"); d1=new Point(x1,y1); d2=new Point(x2,y2); } public Block(Point d1,Point d2) throws RuntimeException { this(d1.getX(),d1.getY(),d2.getX(),d2.getY()); } //Public methods public double area() { Point m=new Point(d1.getX(),d2.getY()); return m.dest(d1)*m.dest(d2); } public double p() { Point m=new Point(d1.getX(),d2.getY()); return 2*(m.dest(d1)+m.dest(d2)); } public boolean isMember(Point p) { return d1.getX()<=p.getX() && p.getX()<=d2.getX() && d2.getY()<=p.getY() && p.getY()<=d1.getY(); } public Object clone() { return new Block((Point)(d1.clone()),(Point)(d2.clone())); } public boolean equals(Object obj) { Block b=(Block)obj; return d1.equals(b.d1) && d2.equals(b.d2); } public String toString() { return "Block="+d1.toString()+","+d2.toString(); } }