Note the following classes should be saved in separate files.
public class Point {
private int x = 0;
private int y = 0;
public Point () {
}
public Point (int x, int y) {
this.x = x;
this.y = y;
}
public Point (Point other) {
x = other.x;
y = other.y;
}
public String toString () {
return "(" + x + "," + y + ")";
}
public static void main (String [] args) {
Point one = new Point();
Point two = new Point(3,6);
Point three = new Point(two);
System.out.println(one + " " + two + " " + three);
return;
}
}
public class Rectangle {
private Point topLeft = null;
private Point bottomRight = null;
public Rectangle () {
this( new Point(0,0), new Point(0,0));
}
public Rectangle (int x1, int y1, int x2, int y2) {
this (new Point(x1, y1), new Point(x2, y2));
}
public Rectangle (Point topLeft, Point bottomRight) {
this.topLeft = new Point(topLeft);
this.bottomRight = new Point(bottomRight);
}
public Rectangle (Rectangle other) {
topLeft = other.topLeft;
bottomRight = other.bottomRight;
}
public String toString () {
return topLeft + "-" + bottomRight;
}
public Rectangle copy() {
return new Rectangle(this);
}
/* Test Driver
*/
public static void main (String [] args) {
String blank = new String(" ");
Rectangle one = new Rectangle();
Rectangle two = new Rectangle(0,0,10,10);
Rectangle three = new Rectangle( new Point(0,0), new Point(5,5));
Rectangle four = new Rectangle(three);
Rectangle five = four.copy();
System.out.println(one + blank + two + blank
+ three + blank + four
+ blank + five);
return;
}
}
public class RectangleDriver {
public static void main (String [] args) {
Point testOne = new Point();
Rectangle testTwo = new Rectangle();
testOne.main( args );
testTwo.main( args );
}
}
/* Sample Run
(0,0) (3,6) (3,6)
(0,0)-(0,0) (0,0)-(10,10) (0,0)-(5,5) (0,0)-(5,5) (0,0)-(5,5)
*/