/* * Paper.java * * Created on April 13, 2003, 3:45 PM */ /** A rectangular piece of paper. The length is always the larger dimension. * The paper can have a rectanglar portion cut out of it, yielding a new * piece of paper, plus new dimensions for the current piece of paper. * */ public class Paper { /** The longer dimension of this piece of paper. */ private double length; /** The shorter dimension of this piece of paper. */ private double width; /** Creates a new instance of Paper. The dimensions given as parameters may be in either order, but the larger is considered to be the length. */ public Paper(double dimension1, double dimension2) { if (dimension1 >= dimension2) { this.length = dimension1; this.width = dimension2; } else { this.length = dimension2; this.width = dimension1; } //end constructor } public double getLength() { return this.length; } public double getWidth() { return this.width; } //////////////////////////////////////////////////////////////////////// /** Return a string representation of a piece of Paper. * Useful for testing */ public String toString() { return "{paper L=" + getLength() + " W=" + getWidth() + "}"; } /** Create a random piece of paper. NOT PART OF THE SOLUTION. */ public static Paper createRandomPaper() { double dim1, dim2; double largestLength = 40.0; double smallestHeight = 1.0; double dimensionRange = largestLength - smallestHeight; dim1 = Math.random() * dimensionRange + smallestHeight; dim2 = Math.random() * dimensionRange + smallestHeight; Paper testPiece = new Paper(dim1, dim2); return testPiece; } //end class Paper }