//package chapter8; /** * Title: Chapter 8, "Class Inheritance and Interfaces" * Description: Examples for Chapter 8 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ // Rectangle.java: The Rectangle class that extends GeometricObject public class Rectangle extends GeometricObject { private double width; private double height; /**Default constructor*/ public Rectangle() { this(1.0, 1.0); } /**Construct a rectangle with width and height*/ public Rectangle(double w, double h) { this(w, h, "white", false); } /**Construct a rectangle with specified width, height, filled, and color*/ public Rectangle(double w, double h, String c, boolean fill) { super(c, fill); width = w; height = h; } /**Return width*/ public double getWidth() { return width; } /**Set a new width*/ public void setWidth(double w) { width = w; } /**Return height*/ public double getHeight() { return height; } /**Set a new height*/ public void setHeight(double h) { height = h; } /**Implement the findArea method in GeometricObject*/ public double findArea() { return width*height; } /**Implement the findPerimeter method in GeometricObject*/ public double findPerimeter() { return 2*(width + height); } /**Override the equals method defined in the Object class*/ public boolean equals(Rectangle rectangle) { return (width == rectangle.getWidth()) && (height == rectangle.getHeight()); } /**Override the toString method defined in the Object class*/ public String toString() { return "[Rectangle] width = " + width + " and height = " + height; } }