// Class that represents a Rectangle as two values, the height and the width, has methods to return these values, the area, the perimeter, // set the two values and a toString to provide info about the Rectangle public class Rectangle { private double width, height; // the two dimensions of the rectangle, stored as doubles public Rectangle() // no arg constructor sets up a default 1x1 rectangle { width = height = 1; } public Rectangle(double w, double h) // normal constructor, is passed in both width and height { if(w<=0) width = 1; // set the values as provided unless the values are illegal, then use 1 as the default else width = w; if(h<=0) height = 1; else height = h; } public double getHeight() { // accessors for height and width return height; } public double getWidth() { return width; } public void setHeight(double h) // mutators for height and width, note the error detection to ensure height/width are positive values { if(h>0) height = h; } public void setWidth(double w) { if(w>0) width = w; } public double getArea() { // computation methods to get the area and perimeter return height * width; } public double getPerimeter() { return height * 2 + width * 2; } public String toString() { // toString to describe this rectangle in full detail return "Height = " + height + "\nWidth = " + width + " \nArea = " + getArea() + "\nPerimeter = " + getPerimeter(); } }