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 Floor plan (1) The Model classes The main c

ID: 3846904 • Letter: E

Question

Exit class

Room class

Building class

Floor plan

(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

FloorBuilderApp.java

import javafx.application.Application;
import java.awt.event.ActionEvent;
import javafx.event.*;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class FloorBuilderApp extends Application {
    public static final String[]    ROOM_COLORS =
            {"ORANGE", "YELLOW", "LIGHTGREEN", "DARKGREEN",         "LIGHTBLUE", "BLUE", "CYAN", "DARKCYAN",         "PINK", "DARKRED", "PURPLE", "GRAY"};

    public void start(Stage primaryStage) {
        colorButton.setOnAction(new EventHandler<ActionEvent>(){
                                    public void handle (ActionEvent actionEvent){
                                        colorButton.setStyle( "-fx-base:" + );
                                    }

                                }
                radiobutton1[i].setOnAction(new EventHandler<ActionEvent>(){

        }

    }
    // Find the number of the button that was clicked

    public void handle(ActionEvent event) {
        int buttonNumber = 0;
        for (buttonNumber = 0; buttonNumber < 4; buttonNumber++) {
            if (buttons[buttonNumber] == event.getSource())
                break;
        }
        int n = 0;
        switch (buttonNumber) {
            case 0: n++; if(n /2 == 0), n / 2 == 1break;
            case 1:break;
            case 2:break;
            case 3:break;

        }
    }

}


FloorBuilderView.java

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import java.awt.*;
import java.awt.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import java.lang.String;
public class FloorBuilderView extends GridPane {
    private RadioButton[] radiobutton1;
    private Button[][] buttons;
    private GridPane aPane;
    private Label label1;
    private Label label2;
    private Label label3;
    private TextField summaryField;
    private Button buildingButton;
    private Button colorButton;
    //get method
    public Button getColorButton(){
        return this.colorButton;
    }
    public void start(Stage primaryStage){
        aPane = new GridPane();
        buttons = new Button[20][20];
        for(int row=0; row<20; row++) {
            for (int col = 0; col < 20; col++) {
                buttons[row][col] = new Button();
                buttons[row][col].relocate(10 + col * 70, 10 + row * 70);
                buttons[row][col].setPrefSize(65, 65);
            }
        }
        FloorPlan fp = new FloorPlan(20, "Main Floor");
        int[][] tiles = {
                        {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                        {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
                        {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
                        {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
                        {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
                        {1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1},
                        {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
                        {1,0,0,0,0,0,1,0,0,0,1,1,1,1,0,1,1,1,1,1},
                        {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
                        {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
                        {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
                        {1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1},
                        {1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
                        {1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
                        {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
                        {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                        {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
                        {1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
                        {1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
                        {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};

        for (int r=0; r<20; r++){
            for (int c=0; c<20; c++) {
                fp.setWallAt(r, c, tiles[r][c] == 1);
                if(tiles[r][c] == 1){
                    buttons[r][c].setStyle( "-fx-base: BLACK;");
                }else{
                    buttons[r][c].setStyle( "-fx-base: WHITE;");
                }
            }
        }
        buttons[0][8].setStyle("-fx-font: 22 arial; -fx-base: RED; -fx-text-fill: WHITE;");
        buttons[0][8].setText("EXIT");
        buttons[9][19].setStyle("-fx-font: 22 arial; -fx-base: RED; -fx-text-fill: WHITE;");
        buttons[9][19].setText("EXIT");
        buttons[19][5].setStyle("-fx-font: 22 arial; -fx-base: RED; -fx-text-fill: WHITE;");
        buttons[19][5].setText("EXIT");

        aPane.setPadding(new Insets(10,10,10,10));
//the labels at the top of each pane
        Label label1 = new Label("FLOOR LAYOUT");
        aPane.add(label1,0,0);
        Label label2 = new Label("SELECT/EDIT");
        aPane.add(label2, 3, 0);
        Label label3 = new Label("FLOOR SUMMARY");
        aPane.add(label3,0,3);
//radio buttons
        ToggleGroup operations = new ToggleGroup();
        radiobutton1 = new RadioButton[4];
        String[] buttonLabels = {"Walls", "Exits", "Room Tiles", "Select Room"};
        for (int i=0; i<4; i++) {
            radiobutton1[i] = new RadioButton(buttonLabels[i]);
            radiobutton1[i].relocate(160, 60 + i*20);
            radiobutton1[i].setPrefSize(150, 20);
            aPane.getChildren().add(radiobutton1[i]);
            radiobutton1[i].setToggleGroup(operations);


                                       // This is the single event handler for all of the radio buttons

        }

        Button buildingButton = new Button("Building Overview");
        buildingButton.relocate(10,50);
        buildingButton.setPrefSize(90, 30);
        aPane.getChildren().add(buildingButton);
        Button colorButton = new Button();
        colorButton.relocate(400,250);
        colorButton.setPrefSize(50,50);
        colorButton.setStyle("-fx-base:LIGHT ORANGE");
        colorButton.setDisable(true);
//textfield
        TextField summaryField = new TextField();
        summaryField.relocate(10,350);
        summaryField.setPrefSize(400,50);
        summaryField.setEditable(true);
        summaryField.setPromptText("Main Floor with 0 rooms");
        aPane.getChildren().add(summaryField);

        primaryStage.setTitle("Floor Plan Builder");
        primaryStage.setResizable(true);
        primaryStage.setScene(new Scene(aPane,600,500));
        primaryStage.show();
    }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Building.java

public class Building {
    public static final int MAXIMUM_FLOORPLANS = 5;
    public static final int MAXIMUM_EXITS = 8;

    private FloorPlan[]   floors;           // The floorPlans of the building
    private int           numFloors;        // The number of floorPlans in the building
    private Exit[]        exits;            // The Exits of the building
    private int           numExits;         // The number of Exits in the building

    public Building(int fCount, int eCount) {
        floors = new FloorPlan[Math.max(MAXIMUM_FLOORPLANS, fCount)];
        numFloors = 0;
        exits = new Exit[Math.max(MAXIMUM_EXITS, eCount)];
        numExits = 0;
    }

    // Get/set methods
    public Exit[] getExits() { return exits; }
    public Exit getExit(int i) { return exits[i]; }
    public FloorPlan[] getFloorPlans() { return floors; }
    public FloorPlan getFloorPlan(int i) { return floors[i]; }

    // Get the exit at this location
    public Exit exitAt(int r, int c) {
        for (int i=0; i<numExits; i++)
            if (exits[i].isAt(r,c))
                return exits[i];
        return null;
    }

    // Retirn whether or not there is an exit at this location
    public boolean hasExitAt(int r, int c) {
        return exitAt(r, c) != null;
    }

    // Add an exit to the floor plan (up until the maximum)
    public boolean addExit(int r, int c) {
        if (numExits < MAXIMUM_EXITS) {
            exits[numExits++] = new Exit(r,c);
            return true;
        }
        return false;
    }

    // Remove an exit from the floor plan
    public void removeExit(int r, int c) {
        // Find the exit
        for (int i=0; i<numExits; i++) {
            if (exits[i].isAt(r,c)) {
                exits[i] = exits[numExits -1];
                numExits--;
                return;
            }
        }
    }

    // Return an example of a building with 1 floor and 3 exits
    public static Building example() {
        Building b = new Building(1, 3);
        b.floors[0] = FloorPlan.floor1();
        b.numFloors = 1;
        b.addExit(19, 5);
        b.addExit(0, 8);
        b.addExit(9, 19);
        return b;
    }
}

Exit.java

import javafx.geometry.Point2D;

public class Exit {
    private Point2D     location;   // The row/column coordinate of the exit in the building

    public Exit(int r, int c) {
        location = new Point2D(r,c);
    }

    public Point2D getLocation() { return location; }
    public void setLocation(Point2D newLoc) { location = newLoc; }

    public boolean isAt(int r, int c) {
        return (location.getX() == r) && (location.getY() == c);
    }
}

FloorPlan.java

public class FloorPlan {
    private static final int    MAX_ROOMS= 12;

    private String          name;               // name of the floor plan
    private int             size;               // # of rows and columns in table
    private boolean[][]     walls;              // Grid indicating whether a wall is there or not
    private Room[]          rooms;              // Rooms defined in the floor plan
    private int             numRooms;           // Number of rooms defined in the floor plan

    // Yep, this is a constructor. It assumes that floorplans are always square in shape
    public FloorPlan(int rw, String n) {
        name = n;
        size = rw;
        walls = new boolean[size][size];
        rooms = new Room[MAX_ROOMS];
        numRooms = 0;

        // Set the grid to have empty space inside, but walls around border
        for (int r=0; r<size; r++)
            for (int c=0; c<size; c++)
                if ((r==0)||(r==size-1)||(c==0)||(c==size-1))
                    walls[r][c] = true;
                else
                    walls[r][c] = false;
    }

    // Some get/set methods
    public int size() { return size; }
    public String getName() { return name; }
    public int getNumberOfRooms() { return numRooms; }

    public boolean wallAt(int r, int c) { return walls[r][c]; }
    public void setWallAt(int r, int c, boolean wall) { walls[r][c] = wall; }

    // Return the room at this position, if this tile position belongs to that room
    public Room roomAt(int r, int c) {
        for (int i=0; i<numRooms; i++) {
            if (rooms[i].contains(r, c))
                return rooms[i];
        }
        return null;
    }

    // Return the room with the given color index, if there is one
    public Room roomWithColor(int index) {
        for (int i=0; i<numRooms; i++) {
            if (rooms[i].getColorIndex() == index)
                return rooms[i];
        }
        return null;
    }

    // Start a new room at the given location
    public Room addRoomAt(int r, int c) {
        if (numRooms < MAX_ROOMS) {
            Room room = new Room();
            rooms[numRooms++] = room;
            room.addTile(r, c);
            return room;
        }
        return null;
    }

    // Remove a room from the floor plan (assumes the room index is valid)
    public void removeRoom(Room r) {
        // Find out which room it is first
        for (int i=0; i<numRooms; i++) {
            if (rooms[i] == r) {
                rooms[i] = rooms[numRooms - 1];
                numRooms--;
                return;
            }
        }
    }

    // Create and return an example of a FloorPlan object
    public static FloorPlan floor1() {
        FloorPlan fp = new FloorPlan(20, "Main Floor");

        int[][] tiles = {
                {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
                {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
                {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
                {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
                {1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1},
                {1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1},
                {1,0,0,0,0,0,1,0,0,0,1,1,1,1,0,1,1,1,1,1},
                {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
                {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
                {1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1},
                {1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1},
                {1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
                {1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
                {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
                {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
                {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
                {1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
                {1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,1},
                {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
        for (int r=0; r<20; r++)
            for (int c=0; c<20; c++)
                fp.setWallAt(r,c,tiles[r][c]==1);

        return fp;
    }
}

Room.java

import javafx.geometry.Point2D;

public class Room {
    private static final int    MAX_ROOM_TILES = 400;

    private int             numTiles;   // The number of tiles that make up a Room
    private Point2D[]       tiles;      // All the tiles that make up a Room
    private int             colorIndex; // The color index of the Room

    public Room() {
        tiles = new Point2D[MAX_ROOM_TILES];
        numTiles = 0;
        colorIndex = 0;
    }

    public int getColorIndex() { return colorIndex; }
    public int getNumberOfTiles() { return numTiles; }
    public void setColorIndex(int c) { colorIndex = c; }

    // Add a tile to the room (up until the maximum)
    public boolean addTile(int r, int c) {
        if (numTiles < MAX_ROOM_TILES) {
            tiles[numTiles++] = new Point2D(c,r);
            return true;
        }
        return false;
    }

    // Remove a tile from the room
    public void removeTile(int r, int c) {
        // Find the tile
        for (int i=0; i<numTiles; i++) {
            if ((tiles[i].getX() == c) && (tiles[i].getY() == r)) {
                tiles[i] = tiles[numTiles -1];
                numTiles--;
                return;
            }
        }
    }

    // Return whether or not the given location is part of the room
    public boolean contains(int r, int c) {
        for (int i=0; i<numTiles; i++)
            if ((tiles[i].getX() == c) && (tiles[i].getY() == r))
                return true;
        return false;
    }
}

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