Answered step by step
Verified Expert Solution
Question
1 Approved Answer
AP CS Floor Plan Lab An app that helps arrange furniture in a room represents the floor plan as a rectangular grid of square cells.
AP CS Floor Plan Lab
An app that helps arrange furniture in a room represents the floor plan as a rectangular grid of square cells. A cell may be not available for placing furniture; for example, it may be near the door or window or too close to another piece of furniture. In the app the grid is represented as a D array of integers; a value of means the cell is empty and available; a value of means the cell is not available. For example:
In this lab you will be writing methods for two separate classes: Location and FloorPlan.
The row and column can be combined in one object of the class Location. The class has a constructor that takes two integer parameters, row and column of the location, and public methods getRow and getCol which return Locations row and column, respectively.
An incomplete Location class is given below:
public class Location
private int upper;
private int left;
public Location int x int y
public boolean equalsObject other
if thisother
return true;
if other instanceof Location
return false;
Location otherLocation other;
return getRowothergetRow && getColothergetCol;
public boolean equalsLocation other
return getRowothergetRow && getColothergetCol;
public String toString return upperleft;
public int getRow
public int getCol
The floor plan is represented in the app by the java class FloorPlan. A partial definition of the FloorPlan class is shown below. You will write five methods of the class and its constructor.
import java.util.;
public class FloorPlan
private int room;
private final int ROWS; number of rows in this floor plan
private final int COLS; number of columns in this floor plan
constructs D array of integers filled with s
public FloorPlanint r int c
public void printRoomprints room as a matrix
public int getRoomreturns room
makes the rc cell unavailable sets the value to
public void eliminateint r int c
if r && r && c whereFitsint width, int height
A rectangular region on a floor plan is described by its top and bottom rows and its left and right columns. For example, the pictures below show two regions:
The first region has top bottom left and right This region on the left is empty because all the cells in it are empty and available for placing furniture the corresponding elements of the room array have values The second region has top bottom left and right This region is NOT empty.
public boolean isEmptyRegionint top, int bottom, int left, int right takes four parameters: the top row, the bottom row, the left column, the right column. The method returns true if all the cells in the region, including the borders, are empty the corresponding values in the array are zeros Make sure to check that all the parameters are within the room limits Also, check whether topbottom and leftright.
A piece of furniture is represented on the floor plan by a rectangle that covers several cells. We call the rectangles horizontal dimensions on the plan width and its vertical dimensions height. The location of the piece on the plan is always identified by the row and column of its upper left corner.
public boolean fitsint width, int height, Location ulCorner returns true if a piece of furniture with given horizontal and vertical dimensions fits at he specified locations in the room. For a piece of furniture to fit, two conditions must be satisfied:
All the cells in the rectangular region under the piece must be within the room limits;
All the cells in a slightly larger rectangular region must be empty. The larger region includes all the cells under the piece and all the adjacent cells that are within the room limits
For example, the following pictures show that a by piece of furniture fits into the floor plan at locations and :
The same piece does NOT fit, for example, at locations and :
public ArrayList whereFitsint width, int height returns an ArrayList of all locations where a piece of furniture with given horizontal and vertical dimensions fits in the room. Process the room in rowcolumn order.
Test your classes thoroughly in the Main.java file. A VERY incomplete tester class is given below:
import java.util.;
public class Main
public static void main String args
FloorPlan m new FloorPlan ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started