Rectangle.java
Select all
/* Rectangle.java CIS 260 2005-02-09 David Klick This is a subclass of the Shape class. To create an object from this class, the abstract methods draw and area had to be implemented. */ import java.awt.Graphics; public class Rectangle extends Shape { private int height, width; public Rectangle() { super(); setHeight(1); setWidth(1); } public Rectangle(int x, int y, int h, int w) { super(x, y); setHeight(h); setWidth(w); } public Rectangle(Rectangle s) { super(s.origin); setHeight(s.height); setWidth(s.height); } public void setHeight(int h) { height = h<0 ? -h : h; } public void setWidth(int w) { width = w<0 ? -w : w; } public double area() { return height * width; } public int getHeight() { return height; } public int getWidth() { return width; } public void draw(Graphics g) { g.drawRect(origin.x, origin.y, width, height); } public String toString() { return origin + ", w=" + width + ", h=" + height; } }