Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exit class Room class Building class (1) The Model classes The main class that r

ID: 3837548 • Letter: E

Question

Exit class

Room class

Building class

(1) The Model classes The main class that represents the model is a Building object. Each building contains various FloorPlan objects which contain Room objects. Buildings also have Exit objects. The picture on the right shows a single FloorPlan which contains 4 colored Room objects. The 3 red squares represent the Building's Exits. The white areas are corridors on that floor. Since the goal of this assignment is to create an application with a resizable user interface that allows the user to create floor plans in a building, all of the model classes are given to you as completed. Please make sure that you understand all of the code that you are given here. You MUST NOT add any code to these model classes, nor change any of it. You MUST hand in these unaltered model classes along with your assignment. An Exit objectis simply a 2D point represented by a (row, column) coordinate with respect to the Building

Explanation / Answer

public class FloorPlan {
private static final int MAX_ROOM = 4;

private int numRooms; // The number of rooms on a Floor
   private Room[]    rooms; // All the rooms on a Floor
  
public FloorPlan() {
rooms = new Room[MAX_ROOM];
       numRooms = 0;
}


public int getNumberOfRooms() { return numRooms; }

// Add a room to the floor (up until the maximum)
public boolean addRoom(int r, int c) {
if (numRooms < MAX_ROOM) {
rooms[numRooms++] = new Room();
           rooms[numRooms].addTile(r,c);
           rooms[numRooms].addTile(r,c+1;
           rooms[numRooms].addTile(r,c+2);
                      
           rooms[numRooms].addTile(r+1,c);
           rooms[numRooms].addTile(r+2,c);
           rooms[numRooms].addTile(r+3,c);

           rooms[numRooms].addTile(r+1,c+1);
           rooms[numRooms].addTile(r+2,c+2);
           rooms[numRooms].addTile(r+3,c+3);

           return true;
}
return false;
}

// Remove a room from the floor
public void removeRoom(int index) {
// Find the tile
for (int i=0; i<numRooms; i++) {
if (i == index) {
rooms[i] = rooms[numRooms -1];
index = i+1
}
}
       if (numRooms > 0)
       {
           rooms[numRooms -1] = null;
           numRooms--;      
       }
}

   public static FloorPlan floor1() {
       FloorPlan fp = new FloorPlan();
       fp.addRoom(1,1);
       fp.addRoom(4,4);
       fp.addRoom(7,7);

       return fp;
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote