Answered step by step
Verified Expert Solution
Link Copied!

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 2D array of integers; a value of 0 means the cell is empty and available; a value of 1 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 equals(Object other){
if (this==other)
return true;
if (!(other instanceof Location))
return false;
Location other1=(Location) other;
return (getRow()==other1.getRow() && getCol()==other1.getCol());
}
public boolean equals(Location other1){
return (getRow()==other1.getRow() && getCol()==other1.getCol());
}
public String toString(){ return "("+upper+","+left+")"; }
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 2D array of integers filled with 0s
public FloorPlan(int r, int c){}
public void printRoom(){}//prints room[] as a matrix
public int [][] getRoom(){}//returns room[]
// makes the (r,c) cell unavailable (sets the value to 1)
public void eliminate(int r, int c){
if ((r>=0 && r=0 && c whereFits(int 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=1, bottom=3, left=2, and right=6. 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 0). The second region has top=5, bottom=7, left=4, and right=6. This region is NOT empty.
public boolean isEmptyRegion(int 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 top<=bottom and left<=right.
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 fits(int 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 4 by 2 piece of furniture fits into the floor plan at locations (2,2),(2,0), and (6,0):
The same piece does NOT fit, for example, at locations (1,2),(2,4), and (6,1):
public ArrayList whereFits(int 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 row-column 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 m1= new FloorPlan (8,9);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago