public boolean isSquare() {
return width == height;
}
public boolean hasInitialDimensions() { /*&& is a logical operator for AND. It means the left expression AND the right expression must be true */ return (width == 0) && (height == 0); }
public boolean isWiderTry1() { //Return true if we are wider (w >= h) //width and height are our ivars if (width > height) return true; else return false; }
public boolean isWider() { /* Improved. Because (width > height) produces a boolean -- so return it without the if/else (not needed) */ return width > height; }
public void doubleSmallestDimension() { /*Note: if dims are equal, okay to double either*/ if (isWider()) height = 2 * height; else width = 2 * width; }
public int getMax() { //return max dimension if (width > height) return width; else return height; }
public int getMin() { //return min dimension if (width < height) return width; else return height; }
/** Returns true if point argument is above of this rectangle */ public boolean isPointAbove(Point p) { return p.getY() < this.leftTop.getY(); }
/** * Returns true if this rectangle contains "otherPoint" * i.e., if "otherPoint" is inside this rectangle */ public boolean contains(Point otherPoint) { int leftX, topY, rightX, bottomY, otherX, otherY; leftX = this.leftTop.getX(); topY = this.leftTop.getY(); rightX = leftX + this.width; bottomY = topY + this.height; otherX = otherPoint.getX(); otherY = otherPoint.getY(); return otherX >= leftX && otherX <= rightX && otherY >= topY && otherY <= bottomY; }
/** * Returns true if this rectangle contains both * Point parameters */ public boolean containsBoth(Point p1, Point p2) { return this.contains(p1) && this.contains(p2); }
public boolean isMaxLargerThan(int length) { //Return true if our max dimension is larger than the param return this.getMax() > length; }
public boolean isMinLargerThan(int length) { //Return true if our min dimension is larger than the param return this.getMin() > length; }
public void print(boolean option) { //if arg is true, print details, else basic if (option) printDetails(); else printDimensions(); } public void printDimensions() { prn("Width: " + width); prn("Height: " + height); } public void printDetails() { //First print the basics printDimensions(); //Now print a rich mix of info about this rec if (width == 0 && height == 0) prn("Dims are initial (condition 1)"); if (hasInitialDimensions()) prn("Dims are initial (condition 2)"); if (width > 10) prn("Width is greater than 10"); if ((width + height) > 20) prn("Dim sum is greater than 20"); if (isWider()) prn("Greater width than height"); else prn("Not greater width than height"); }