/** * A class for representing a rectangle. Each rectangle has a width and height. * * @author Franck van Breugel */ public class Rectangle { private int width; private int height; /** * Initializes this rectangle with the given width and height. * * @param width width of this rectangle. * @param height height of this rectangle. */ public Rectangle(int width, int height) { this.width = width; this.height = height; } /** * Initializes this rectangle with zero width and height. */ public Rectangle() { this.width = 0; this.height = 0; } /** * Initializes this rectangle with the same width and height as the given rectangle. * * @param rectangle the rectangle to be copied. */ public Rectangle(Rectangle rectangle) { this.width = rectangle.width; this.height = rectangle.height; } /** * Returns the width of this rectangle. * * @return the width the width of this rectangle. */ public int getWidth() { return this.width; } /** * Returns the height of this rectangle. * * @return the height of this rectangle. */ public int getHeight() { return this.height; } /** * Returns the area of this rectangle. * * @return the area of this rectangle. */ public int getArea() { return this.width * this.height; } /** * Returns a string representation of this rectangle. For example, the string representation of new Rectangle(1, 2) * is "Rectangle of width 1 and height 2". * * @return a string representation of this rectangle. */ public String toString() { return "Rectangle of width " + this.width + " and height " + this.height; } /** * Scales this rectangle with the given factor. * * @param factor the scaling factor. */ public void scale(int factor) { this.width = this.width * factor; this.height = this.height * factor; } }