All pastes #755219 Raw Edit

House.java

public java v1 · immutable
#755219 ·published 2007-10-30 15:40 UTC
rendered paste body
import java.awt.*;import java.util.*;public class House {		public House(Point aPoint)	 /*	 Construct the House so that its upper left corner is at	 the given Point.	 */	 {		 this.origin = new Point(aPoint);		 this.hausVektor = new Vector();		 		 this.addWindow();		 this.addWindow();		 this.addDoor();		 this.addDoor();		 this.addWindow();		 this.addWindow();		 	 }		public void draw(Graphics graphics)	 /*	 Draw myself on the given Graphics.	 */	 {		 graphics.drawRect(this.origin.x,this.origin.y,190,50);		 graphics.drawLine(this.origin.x,this.origin.y,this.origin.x+95,this.origin.y-50);		 graphics.drawLine(this.origin.x+95,this.origin.y-50,this.origin.x+190,this.origin.y);		 int index;		 for (index = 0; index < this.hausVektor.size(); index++) {			 Object component;			 component = this.hausVektor.get(index);			 Door door;			 Window window;			 if (component instanceof Window)			 {			 window = (Window) component;			 window.draw(graphics);			 }			 else			 {			 door = (Door) component;			 door.draw(graphics);			 }		 }			 }		 public void addWindow()	 /*	 Create and add a new Window to me, 10 pixels	 to the right of my last Door or Window. If I	 have no Doors or Windows yet, add the Window 10 pixels	 to the right of my left wall. If the new Window	 will not fit in the house, add it anyway.	 */	 {		 Window aWindow;		 Point aWindowPoint;		 int size = hausVektor.size();		 aWindowPoint = new Point(size+10, this.origin.y+10);		 aWindow = new Window(aWindowPoint);		 this.hausVektor.add(aWindow);	 }	 public void addDoor()	 /*	 Create and add a new Door to me, 10 pixels to	 the right of my last Door or Window. If I have	 no Doors or Windows yet, add the Door 10 pixels	 to the right of my left wall. If the new Door	 will not fit in the house, add it anyway.	 */	 {		 Door aDoorIAdore;		 Point aPointIAdore;		 int size = hausVektor.size();		 aPointIAdore = new Point(size+10, this.origin.y+10);		 aDoorIAdore = new Door(aPointIAdore);		 this.hausVektor.add(aDoorIAdore);	 }		/* Instance variables */	private Point origin;	private Vector hausVektor;}