import java.util.Scanner; import becker.robots.*; /** A subclass of City that includes a method for placing rectangles * made of walls. * * @author Mary Elaine Califf * */ public class RectangleCity extends City { /** * Default constructor */ public RectangleCity() { super(); } /** Constructor allowing specification of the size of the city as * initially visible * @param numVisStreets * Number of streets initially visible * @param numVisAvenues * Number of avenues initially visible */ public RectangleCity(int numVisStreets, int numVisAvenues) { super(numVisStreets,numVisAvenues); } /** Creates a rectangle out of walls in the city * @param top * The location of the top row of intersections inside the rectangle * @param left * The location of the left most column of intersections inside the rectangle * @param height * The height of the rectangle * @param width * The width of the rectangle */ public void makeRectangle(int top, int left, int height, int width) { // lay out the vertical walls for (int i = top; i < top+height; i++) { new Wall(this,i,left,Direction.WEST); new Wall(this,i,left+width-1,Direction.EAST); } // lay out the horizontal walls for (int i = left; i < left+width; i++) { new Wall(this,top,i,Direction.NORTH); new Wall(this,top+height-1,i,Direction.SOUTH); } } }