/* AUTHOR: Sandy Bartlett COURSE: SI 543 PROJECT: OO programming assignment DUE DATE: Feb. 16, 2001 SUBMISSION DATE: Feb. 11, 2001 SUMMARY A class that represents a grass hut. Grass huts are single storey dwellings. Price will be specified at the time of sale, except for grass huts in the subdivision, which have a suggested retail price. INPUT none BAD DATA CHECKING: If the hut is bigger than the land, it will be made to fit the land. If the number of smoke holes is too large, it will be set to the maximum number of holes for the size of the hut. OUTPUT The draw method draws a representation of the hut on a Graphics object. CLASS HIERARCHY Object - House - GrassHut ASSUMPTIONS The specified land area will be greater than or equal to the minimum room size; sizes will be in square meters; huts are square. Room sizes will not be negative. */ import java.awt.*; class GrassHut extends House { public static final String AREA_UNITS = " square meters"; private static final String MATERIAL = "grass"; private static final int MIN_ROOM_SIZE = 4; private int smokeHoles = 1; // your basic, bottom-of-the-line hut public GrassHut() { super(8, 6, MATERIAL, Color.green, 1); } // default constructor // hut in our subdivision public GrassHut(int rooms) { this(16, rooms > 4 ? 16 : MIN_ROOM_SIZE * rooms, rooms, 1); setPrice((float)(19.95 + 20 * rooms)); } // constructor - rooms // basic hut on owners land public GrassHut(float landArea, float size) { super(landArea, size > landArea ? landArea : size, MATERIAL, Color.green, 1); } // constructor - land, size // rich person's hut on their land public GrassHut(float landArea, float size, int rooms) { this(landArea, size, rooms, 1); } // constructor - land, size, rooms // for multifamily huts public GrassHut(float landArea, float size, int rooms, int holes) { super(landArea, size > landArea ? landArea : size, MATERIAL, Color.green, rooms); int possibleHoles = (int)(Math.sqrt(getSize())) * 50 / 40 - 1; if (holes > possibleHoles) holes = possibleHoles; smokeHoles = holes; } // constructor - land, size, rooms, holes public void draw(Graphics g) { Color oldColor = g.getColor(); int hutDrawWidth = (int)(Math.sqrt(getSize())) * 50; int [] roofX = {20, hutDrawWidth / 2 + 20, hutDrawWidth + 20}; int [] roofY = {100, 5, 100}; // draw the hut and the roof g.setColor(getColor()); g.fillRect(20, 100, hutDrawWidth, 100); g.fillPolygon(roofX, roofY, 3); // draw the door g.setColor(Color.black); g.fillRect(50, 130, 40, 70); // draw the smoke holes if (smokeHoles == 1) g.fillOval(hutDrawWidth / 2 + 20, 50, 20, 20); else for (int i = 0; i < smokeHoles; i++) g.fillOval(100 + 40 * i, 50, 20, 20); g.setColor(oldColor); } // draw public int getSmokeHoles() { return smokeHoles; } // getSmokeHoles public void setSmokeHoles(int holes) { if (holes >= 0) { int possibleHoles = (int)(Math.sqrt(getSize())) * 50 / 40 - 1; if (holes <= possibleHoles) smokeHoles = holes; } // if } // setSmokeHoles } // GrassHut