1 /* 2 * A program that computes the area of a desk not obscured by any object. 3 * 1. Introduce a variable for each of the given variables and bind these variables to the measurements 4 * 2. Create 6 "objects to think with" from the NPW: one for the desk, one for the book, one for the lab 5 * manual, one for a plate, one for a can, and one for a coaster. Introduce variables for each and 6 * appropriately bind the variables to the objects (Constraint: Do not use an explicit constructor 7 * to construct the coaster - ask the can to produce the coaster). 8 * 3. Introduce a variable and bind it to the collective area of the objects on the desk 9 * 4. Introduce a variable and bind it to the result - the area of the desk not obscured by the objects 10 * which sit on top of it. 11 * 5. Display the result to the standard output stream, being sure to give it a label. 12 */ 13 package shapes; 14 15 public class MessyDesk { 16 public static void main(String[] args) { 17 //desk measurements 18 double deskHeight = 66.0; 19 double deskWidth = 153.0; 20 21 //notebook measurements (there's 2) 22 double notebookHeight = 29.7; 23 double notebookWidth = 21.0; 24 25 //lab manual measurements 26 double labManualHeight = 30.48; 27 double labManualWidth = 25.4; 28 29 //can measurements (there's 3 sitting on top of coasters (circumscribing square of can = coaster)) 30 double canRadius = 2.52; 31 32 //dinner plate measurements (there's 9) 33 double plateDiameter = 20.6; 34 double plateRadius = (plateDiameter/2); 35 36 //Create objects to think with 37 SRectangle desk = new SRectangle(deskHeight, deskWidth); 38 SRectangle notebook = new SRectangle(notebookHeight, notebookWidth); 39 SRectangle labManual = new SRectangle(labManualHeight, labManualWidth); 40 SCircle plate = new SCircle(plateRadius); 41 SCircle can = new SCircle(canRadius); 42 SSquare coaster = can.circumscribingSquare(); 43 44 //Get area of all objects not including the desk 45 double deskObjectsArea = ((2 * notebook.area()) + (9 * plate.area()) + (3 * coaster.area()) + labManual.area()); 46 47 //Get desk area 48 double deskArea = desk.area(); 49 50 //Get area of a desk not obscured by any object 51 double notObscuredDeskArea = (deskArea - deskObjectsArea); 52 53 //Display result to output stream 54 System.out.println("The area of a desk not obscured by any object: " + notObscuredDeskArea); 55 } 56 } 57