package cse1030; import java.awt.Color; import princeton.introcs.StdDraw; /** * A rectangle shape. A rectangle has a width and height greater than zero. * * @author CSE1030Z * */ public class Rectangle extends Shape { /** * Create a rectangle with position (0, 0), color blue, width 1, and height 2. */ public Rectangle() { // make sure to call the superclass constructor first } /** * Create a rectangle with position (x, y), and the given width, height, and color. * * @param x the x coordinate of the position of the rectangle * @param y the y coordinate of the position of the rectangle * @param width the width of the rectangle * @param height the height of the rectangle * @param color the color of the rectangle * @throws IllegalArgumentException if the width or height is zero or negative */ public Rectangle(double x, double y, double width, double height, Color color) { // make sure to call the superclass constructor first } /** * Create a rectangle with the given position, width, height, and color. * * @param position the position of the rectangle * @param width the width of the rectangle * @param height the height of the rectangle * @param color the color of the rectangle * @throws IllegalArgumentException if the width or height is zero or negative */ public Rectangle(Point2D position, double width, double height, Color color) { // make sure to call the superclass constructor first } /** * Get the width of the rectangle. * * @return the width of the rectangle. */ public double getWidth() { } /** * Set the width of the rectangle. The width must be greater than zero. * * @param newWidth the new width of the rectangle * @throws IllegalArgumentException if the new width is zero or negative */ public void setWidth(double newWidth) { } /** * Get the height of the rectangle. * * @return the height of the rectangle. */ public double getHeight() { } /** * Set the height of the rectangle. The height must be greater than zero. * * @param newHeight the new height of the rectangle * @throws IllegalArgumentException if the new height is zero or negative */ public void setHeight(double newHeight) { } /** * Returns a string representation of the rectangle. * *

* The string returned has the form: * *

* position: (x, y), color: (r, g, b), width: W, height: H where x * and y are the coordinates of the position, * r, g, and b are the * red, green, and blue components of the color in the range 0-255, * W is the width, and H is the height. * * @return a string representation of the rectangle */ @Override public String toString() { // use super.toString } /** * Draws a filled rectangle to StdDraw using the * position, width, height, and color of this rectangle. */ @Override public void draw() { // use StdDraw.setPenColor // then use StdDraw.filledRectangle } }