Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In java please, show the correct code and output of question 4 and 5 because they are relate to each other, here is some code

In java please, show the correct code and output of question 4 and 5 because they are relate to each other, here is some code you need and will help.

image text in transcribedimage text in transcribedimage text in transcribed

here is the code you need:

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 
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; rMAX_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 
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); } } 
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; iMAXIMUM_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; ifloor1(); b.floors[1] = FloorPlan.floor2(); b.floors[2] = FloorPlan.floor3(); b.floors[3] = FloorPlan.floor4(); b.floors[4] = FloorPlan.floor5(); b.numFloors = 5; b.addExit(19, 5); b.addExit(0, 8); b.addExit(9, 19); return b; } } 
import javafx.geometry.HPos; import javafx.geometry.VPos; import javafx.scene.control.*; import javafx.scene.layout.GridPane; import javafx.scene.layout.Pane; import javafx.geometry.Insets; public class FloorBuilderView extends GridPane { public static final String[] ROOM_COLORS = {"ORANGE", "YELLOW", "LIGHTGREEN", "DARKGREEN", "LIGHTBLUE", "BLUE", "CYAN", "DARKCYAN", "PINK", "DARKRED", "PURPLE", "GRAY"}; // These are the tiles and buttons private GridPane tiles; private Button[][] buttons; private RadioButton editWallsButton; private RadioButton selectExitsButton; private RadioButton editRoomsButton; private RadioButton defineRoomsButton; private Button colorButton; private Button overviewButton; private TextField summaryField; public Button getFloorTileButton(int r, int c) { return buttons[c][r]; } public Pane getTilePanel() { return tiles; } public RadioButton getEditWallsButton() { return editWallsButton; } public RadioButton getSelectExitsButton() { return selectExitsButton; } public RadioButton getEditRoomsButton() { return editRoomsButton; } public RadioButton getDefineRoomsButton() { return defineRoomsButton; } public Button getRoomColorButton() { return colorButton; } public Button getBuildingOverviewButton() { return overviewButton; } public TextField getSummaryField() { return summaryField; } private Building model; public FloorBuilderView(Building m) { model = m; // Setup the pane with the floor plan buttons buttons = new Button[model.getFloorPlan(0).size()][model.getFloorPlan(0).size()]; tiles = new GridPane(); tiles.setPadding(new Insets(0, 0, 0, 10)); for (int r=0; rsetMargin(label, new Insets(0, 0, 0, 10)); label = new Label("SELECT/EDIT:"); add(label,1,0,1,1); label.setMinHeight(30); label.setMinWidth(100); setMargin(label, new Insets(0, 0, 0, 0)); label = new Label("FLOOR SUMMARY:"); add(label,0,7,1,1); label.setMinHeight(30); label.setMinWidth(100); setMargin(label, new Insets(0, 0, 0, 10)); // Add the Editting buttons ToggleGroup operations = new ToggleGroup(); editWallsButton = new RadioButton("Walls"); editWallsButton.setToggleGroup(operations); editWallsButton.setSelected(true); add(editWallsButton,1,1,2,1); editWallsButton.setMinHeight(30); editWallsButton.setMinWidth(70); setMargin(editWallsButton, new Insets(0, 0, 0, 20)); selectExitsButton = new RadioButton("Exits"); selectExitsButton.setToggleGroup(operations); add(selectExitsButton,1,2,2,1); selectExitsButton.setMinHeight(30); selectExitsButton.setMinWidth(70); setMargin(selectExitsButton, new Insets(0, 0, 0, 20)); editRoomsButton = new RadioButton("Room Tiles"); editRoomsButton.setToggleGroup(operations); add(editRoomsButton,1,3,1,1); editRoomsButton.setMinHeight(30); editRoomsButton.setMinWidth(80); setMargin(editRoomsButton, new Insets(0, 20, 0, 20)); defineRoomsButton = new RadioButton("Select Room"); defineRoomsButton.setToggleGroup(operations); add(defineRoomsButton,1,4,2,1); defineRoomsButton.setMinHeight(30); defineRoomsButton.setMinWidth(80); setMargin(defineRoomsButton, new Insets(0, 20, 0, 20)); // Add the room color label colorButton = new Button(); add(colorButton,2,3,1,1); colorButton.setMinHeight(30); colorButton.setMinWidth(30); colorButton.setPrefWidth(30); colorButton.setStyle("-fx-base: WHITE;"); setMargin(colorButton, new Insets(0, 10, 0, 0)); // Add the Building Overview button overviewButton = new Button("Building Overview"); add(overviewButton,1,5,2,1); overviewButton.setMinHeight(30); overviewButton.setMinWidth(140); overviewButton.setPrefWidth(140); setMargin(overviewButton, new Insets(20, 0, 0, 10)); setValignment(overviewButton, VPos.TOP); setHalignment(overviewButton, HPos.LEFT); // Add the summary Field summaryField = new TextField(""); add(summaryField,0,8,3,1); summaryField.setMinHeight(30); summaryField.setMinWidth(300); summaryField.setEditable(false); setMargin(summaryField, new Insets(0, 10, 10, 10)); } public void update(int currentFloor, int currentColor) { int dimension = model.getFloorPlan(currentFloor).size(); // Update the Room Color Button colorButton.setDisable(!editRoomsButton.isSelected()); colorButton.setStyle("-fx-base: " + ROOM_COLORS[currentColor] + ";"); // Update the walls, exits and room colors for (int r=0; rROOM_COLORS[off.getColorIndex()] + ";"); } else { buttons[r][c].setText(""); buttons[r][c].setStyle("-fx-base: WHITE;"); } } } // Update the summary field summaryField.setText(model.getFloorPlan(currentFloor).getName() + " with " + model.getFloorPlan(currentFloor).getNumberOfRooms() + " rooms."); } } 
import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class FloorBuilderApp extends Application { private FloorBuilderView view; private Building model; private int currentFloor; // Index of the floor being displayed private int currentColor; // Index of the current room color public void start(Stage primaryStage) { model = Building.example(); currentFloor = 0; currentColor = 0; VBox aPane = new VBox(); view = new FloorBuilderView(model); view.setPrefWidth(Integer.MAX_VALUE); view.setPrefHeight(Integer.MAX_VALUE); aPane.getChildren().add(view); primaryStage.setTitle("Floor Plan Builder"); primaryStage.setScene(new Scene(aPane, 370,320)); primaryStage.show(); // Plug in the floor panel event handlers: for (int r=0; r() { public void handle(ActionEvent event) { handleTileSelection(event); }}); } } // Plug in the radioButton event handlers view.getEditWallsButton().setOnAction(new EventHandler() { public void handle(ActionEvent event) { view.update(currentFloor, currentColor); }}); view.getSelectExitsButton().setOnAction(new EventHandler() { public void handle(ActionEvent event) { view.update(currentFloor, currentColor); }}); view.getEditRoomsButton().setOnAction(new EventHandler() { public void handle(ActionEvent event) { view.update(currentFloor, currentColor); }}); view.getDefineRoomsButton().setOnAction(new EventHandler() { public void handle(ActionEvent event) { view.update(currentFloor, currentColor); }}); // Plug in the office color button view.getRoomColorButton().setOnAction(new EventHandler() { public void handle(ActionEvent event) { currentColor = (currentColor + 1)%view.ROOM_COLORS.length; view.update(currentFloor, currentColor); }}); view.update(currentFloor, currentColor); } // Handle a Floor Tile Selection private void handleTileSelection(ActionEvent e) { // Determine which row and column was selected int r=0, c=0; OUTER: for (r=0; rlaunch(args); } } 
(4) The BuildingDialog D Building Overview X Create a class called BuildingDialog that brings up the following dialog box when the user presses the Building overview button from the main Num Floors: user interface: Num Exits: The dialog box should show the number of floors in the building, as well as the current number of exits and rooms in the entire building. It should Num Rooms: 33 also show the total square footage of the building which is the number of non-wall floor tiles throughout the whole building. The text fields should Total Size 1330 sq. Ft. not be editable. You can test your dialog's data by adding or removing rooms, exits and walls and make sure that these values change. When Directory Listing the user presses the OK button, the dialog box should close OK When the user presses the Directory Listing button, a DirectoryDialog should appear (see next part of assignment) while the BuildingDialog remains open. (5) The DirectoryDialog Create a class called DirectoryDialog that brings up the following dialog box when the user presses the Directory Listing button from the BuildingDialog The Dialog contains a ListView DE Directory Listing that displays information about the rooms 102 Sam Pull (Human Resources Manager) of the building. Each entry in the list should correspond to a Room in the 104 Tim Burr (Receptionist) building. Hence, if there are no rooms, 202 Clara Net (Programmer) then this list will be empty. Each entry 204 Mary Me (Programmer should show the number of the room, the occupant of the room, and the position 206 June Bugs (Programmer) that that occupant holds in the company 302 Tom Cat (Systems Analyst) The text must be formatted as shown in (4) The BuildingDialog D Building Overview X Create a class called BuildingDialog that brings up the following dialog box when the user presses the Building overview button from the main Num Floors: user interface: Num Exits: The dialog box should show the number of floors in the building, as well as the current number of exits and rooms in the entire building. It should Num Rooms: 33 also show the total square footage of the building which is the number of non-wall floor tiles throughout the whole building. The text fields should Total Size 1330 sq. Ft. not be editable. You can test your dialog's data by adding or removing rooms, exits and walls and make sure that these values change. When Directory Listing the user presses the OK button, the dialog box should close OK When the user presses the Directory Listing button, a DirectoryDialog should appear (see next part of assignment) while the BuildingDialog remains open. (5) The DirectoryDialog Create a class called DirectoryDialog that brings up the following dialog box when the user presses the Directory Listing button from the BuildingDialog The Dialog contains a ListView DE Directory Listing that displays information about the rooms 102 Sam Pull (Human Resources Manager) of the building. Each entry in the list should correspond to a Room in the 104 Tim Burr (Receptionist) building. Hence, if there are no rooms, 202 Clara Net (Programmer) then this list will be empty. Each entry 204 Mary Me (Programmer should show the number of the room, the occupant of the room, and the position 206 June Bugs (Programmer) that that occupant holds in the company 302 Tom Cat (Systems Analyst) The text must be formatted as shown in

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

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions