A new academic building has been constructed in the center of a certain University Campus located at the western edge of a certain Midwestern state. This building has three elevators. Your job is to write a program to simulate this buildings elevator system.
The building has three elevators which are known as N, S and W. Each elevator has two doors which are known as F (for Front) and B (for Back) and each of these doors is either open or closed at any point in time. Each elevator will service floors 0 through 3 where floor 0 is the basement and floor 3 is the upper-most floor. Due to the architectural design, each elevator uses only door F for floors 0 and 2 while using only door B for floors 1 and 3. If, for example, someone tries to open the front door while on floor 3, the front door will not open.
For this exercise, we will not consider partial states (i.e. the elevator will never be between floors, the doors will never be partly open, and people will never be halfway in or out of the elevator). At any specific point in time, we will assume that the elevator is on a single floor (0 through 3) and that each door is either fully open or fully closed. We also assume that each elevator has as capacity of only 8 people and hence there will never be more than 8 people in any elevator.
You must write a program that allows users to ‘control’ the elevators of the building. Your program, when run, must 1) print a menu of operations 2) read the users input indicating what operation they wish to apply and 3) print the state that results from applying the selected operation. The example output shown below must be followed exactly.
Below is a sample run of the program. The output must be formatted exactly as given below.
Select elevator: N MENU: 0) Move up one floor 1) Move down one floor 2) Open Front door 3) Close Front door 4) Open Back door 5) Close Back door 6) People enter 7) People leave Menu choice: 6 How many people? 5 STATE: N – Floor:3;Front:closed;Back:open;People:8 S – Floor:0;Front:closed;Back;closed;People:2 W – Floor:2;Front:open;Back;closed;People:0 Select Elevator: W MENU: 0) Move up one floor 1) Move down one floor 2) Open Front door 3) Close Front door 4) Open Back door 5) Close Back door 6) People enter 7) People leave Menu choice: 0 ERROR: Illegal operation. STATE: N – Floor:3;Front:closed;Back:open;People:8 S – Floor:0;Front:closed;Back;closed;People:2 W – Floor:2;Front:open;Back;closed;People:0 Select Elevator: W MENU: 0) Move up one floor 1) Move down one floor 2) Open Front door 3) Close Front door 4) Open Back door 5) Close Back door 6) People enter 7) People leave Menu choice: 3 STATE: N – Floor:3;Front:closed;Back:open;People:8 S – Floor:0;Front:closed;Back;closed;People:2 W – Floor:2;Front:closed;Back;closed;People:0 ...
You must implement the two UML class diagrams shown below. You must write a class named ElevatorModel
that models a single elevator in the academic building. You must also write a class named BuildingController
that has a main method and three instance variables of type ElevatorModel
.
BuildingController
.ElevatorModel
class.ElevatorModel |
// attributes not shown but belong here |
+ElevatorModel() // the elevator is on floor 0 with no people and doors are closed |
+int getFloor() // returns the floor number [0-3] |
+boolean frontIsOpen() //returns true if the front door is open and false otherwise |
+boolean backIsOpen() //returns true if the back door is open and false otherwise |
+int getOccupantCount() //returns the number of people in the elevator |
+boolean moveUp() // moves the elevator one floor up if possible (not at top floor and all doors closed) |
+boolean moveDown() // moves the elevator one floor down if possible (not at bottom floor and all doors are closed) |
+boolean loadPeople(int n) // n people enter the elevator if possible (a door is open and there is room for all n) |
+boolean exitPeople(int n) // n people leave the elevator if possible (a door is open) |
+boolean closeFront() // the front door is closed (works even if the front is already closed) |
+boolean openFront() // the front door is opened if possible (works even if the front is already opened) |
+boolean closeBack() // the back door is closed (works even if the back is already closed) |
+boolean openBack() // the back door is opened if possible (works even if the back is already opened) |
BuildingController |
-static ElevatorModel elevatorN, elevatorS, elevatorW; |
+static void main(String[] args)
// main method |
+static ElevatorModel getSelectedElevator()
// prints ‘select elevator’ menu and returns the elevator that the user indicates |
+static int getMainMenuChoice()
// prints the main menu and returns user selection |
+static boolean applyOperation(int menuChoice, ElevatorModel elevator)
// applies the operation indiciated by ‘menuChoice’ to the ‘elevator’ object.
// If the menuchoice is load/exit people, more user input is obtained.
// The method returns true if the operation is successful and false otherwise. |
+static void printState()
// prints the state |
Email only two java files. Make sure they are sent as attachments.