CS1011
Class Exercise
## UML Class Diagram <!--div style="margin: 0 auto"> <div style="float: left; margin: 0; width: 50%"> <table style="border: 2px solid black; font-family: menlo, monaco, consolas, monospace"> <tr> <td style="text-align: center">RectangleRunner</td> </tr> <tr> <td>&nbsp;</td> </tr> <tr> <td> +<u>main(args: String[]): void</u><br /> +<u>createRectangle(in: Scanner): Rectangle</u><br /> ... </td> </tr> </table> </div--> <div style="float: center; margin: 0; width: 50%"> <table style="border: 2px solid black; font-family: menlo, monaco, consolas, monospace"> <tr> <td style="text-align: center">Rectangle</td> </tr> <tr> <td> -width: double<br /> -height: double<br /> </td> </tr> <tr> <td> +Rectangle(width: double, height: double)<br /> +Rectangle(dimensions: String)<br /> +Rectangle()<br /> +setWidth(width: double): boolean<br /> +setHeight(height: double): boolean<br /> +getWidth(): double<br /> +getHeight(): double<br /> +getArea(): double<br /> +getPerimeter(): double<br /> </td> </tr> </table> </div> </div> ## Step 1 Create the `Rectangle` class and implement all of the required method stubs. (Just declare the methods but leave the contents blank or returning a default value.) ## Step 2 Implement a class to test the `Rectangle` class. ## Step 3 Implement the accessors and mutators. The mutators should do nothing if an invalid value is passed as a dimension. The mutators return a boolean value indicating if the value was changed. ## Step 4 Update the class to test the additional functionality in the `Rectangle` class. ## Step 5 Implement the constructors: * The two-arg constructor creates a rectangle with the specified dimensions unless either value is non-positive. In that case, a unit square should be created. * The constructor that accepts a `String` should extract the width and height from a String in the following format: "w x h" * The no-arg constructor should create a rectangle with randomized dimensions in the range: [0.1, 10) x (0, 5] ## Step 6 Update the class to test the additional functionality in the `Rectangle` class. ## Step 7 Implement `getArea()` and `getPerimeter()`. ## Step 8 Update the class to test the additional functionality in the `Rectangle` class. ## Step 9 Update the `Rectangle` class to display nicely when an instance is passed to `System.out.println()`. ## Step 10 Update the `Rectangle` class so that two rectangles are considered equal if the area of each rectangle is within 0.0001 of each other.

Tuesday, 29-Oct-2019 08:38:23 EDT