/** * * @author nickgrifasi * @version 9/20/21 Rectangle class describes properties of Rectangle and used * for further abstraction purposes. */ public class Rectangle { private String name; private int xCord; private int yCord; private int width; private int height; /** * Constructor for Rectangle class. Builds name and overall dimensions of * Rectangle object. * * @param recName name of rectangle * @param x x coordinate of rectangle * @param y y coordinate of rectangle * @param recWidth width of rectangle * @param recHeight height of rectangle */ public Rectangle(String recName, int x, int y, int recWidth, int recHeight) { name = recName; xCord = x; yCord = y; width = recWidth; height = recHeight; } /** * Getter method that returns the name parameter of a Rectangle object * @return string representing rectangles name */ public String getName() { return name; } /** * Getter method that returns the x coordinate * parameter of a Rectangle object * @return int representing rectangles x-coordinate */ public int getX() { return xCord; } /** * Getter method that returns the y coordinate * parameter of a Rectangle object * @return int representing rectangles y-coordinate */ public int getY() { return yCord; } /** * Getter method that returns the width coordinate * parameter of a Rectangle * object * @return int representing rectangles width */ public int getWidth() { return width; } /** * Getter method that returns the height coordinate * parameter of a Rectangle * object * @return int representing rectangles height */ public int getHeight() { return height; } /** * Equality method for comparing Rectangle position/dimension. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if ((obj == null) || (obj.getClass() != this.getClass())) { return false; } Rectangle quad = (Rectangle) obj; return this.getX() == quad.getX() && this.getY() == quad.getY() && this.getWidth() == quad.getWidth() && this.getHeight() == quad.getHeight(); } /** * @param quad representing the rectangle you want to find the intersection * with the current rectangle. * @return boolean representing if an intersection was found */ public boolean findIntersection(Rectangle quad) { if (this.equals(quad)) { return true; } return !((this.getX() + this.getWidth() <= quad.getX()) || (this.getY() + this.getHeight() <= quad.getY()) || (quad.getX() + quad.getWidth() <= this.getX()) || (quad.getY() + quad.getHeight() <= this.getY())); } /** * Method that returns properties of the Rectangle in * String format. Useful for printing to System.out * @return String representing the rectangles dimensions * in string formatting */ public String toString() { return xCord + ", " + yCord + ", " + width + ", " + height; } }