// CSE 143, Homework 1, Rectangle-Rama // This provided class implements a new type of objects representing rectangles. import java.awt.*; /** Each Rectangle object represents a 2D rectangle with a top-left x/y coordinate, width, height, and fill color. */ public class Rectangle { private int x; // top-left x/y private int y; private int width; private int height; private Color color; // fill color /** Constructs a new rectangle with the given coordinates, size, and color. */ public Rectangle(int x, int y, int w, int h, Color c) { this.x = x; this.y = y; this.width = w; this.height = h; this.color = c; } /** Draws this rectangle using the given graphics pen. */ public void draw(Graphics g) { g.setColor(color); g.fillRect(x, y, width, height); g.setColor(Color.BLACK); g.drawRect(x, y, width, height); } /** Returns this rectangle's leftmost x coordinate. */ public int getX() { return x; } /** Returns this rectangle's topmost y coordinate. */ public int getY() { return y; } /** Returns this rectangle's width. */ public int getWidth() { return width; } /** Returns this rectangle's height. */ public int getHeight() { return height; } /** Returns this rectangle's color. */ public Color getColor() { return color; } /** Returns a text representation of this rectangle, such as "(x=57,y=148,w=26,h=53)". */ public String toString() { return "(x=" + x + ",y=" + y + "),w=" + width + ",h=" + height + ")"; } }