1 public class Rectangle {
2 public int width = 0;
3 public int height = 0;
4 public Point origin;
5
6 // four constructors
7 public Rectangle() {
8 origin = new Point(0, 0);
9 }
10 public Rectangle(Point p) {
11 origin = p;
12 }
13 public Rectangle(int w, int h) {
14 this(new Point(0, 0), w, h);
15 }
16 public Rectangle(Point p, int w, int h) {
17 origin = p;
18 width = w;
19 height = h;
20 }
21
22 // a method for moving the rectangle
23 public void move(int x, int y) {
24 origin.x = x;
25 origin.y = y;
26 }
27
28 // a method for computing the area of the rectangle
29 public int area() {
30 return width * height;
31 }
32 }
Generated with
vim2html
Copyright © 2003-2004 by Chip Cuccio
<http://norlug.org/~chipster/finger>