Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

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, of course, 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 door F for floors 0 and 2 while using door B for floors 1 and 3. If, for example, someone tries to open the back door while on floor 3, the back 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.

Select which elevator to control: 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;open;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.

You may add additional methods to either class.

You must not add instance variables to the BuildingController.

You may add instance variables to the Elevator class.

Each operation is atomic which means that either the entire operation works perfectly or it doesnt work

at all. For example, if 4 people were on the elevator and 6 attempted to load onto the elevator nobody

would enter since there isnt enough capacity.

Whenever an operation cannot be completed, you should print "ERROR: Illegal Operation" and then print

the state. This is illustrated in the example above.

Each of the boolean valued operation methods return true if the operation was successful and false if it

was not. For example, the method named moveUp will return true if the elevator moved up one floor otherwise the method will return false to indicate that the elevator could not moveUp.

ElevatorModel

+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 (either all n enter or none enter)

+boolean exitPeople(int n) // n people leave the elevator if possible (either all n exit or none exit)

+boolean closeFront() // the front door is closed (works even if the front is already closed) +boolean openFront() // the front door is opened (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 (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 getFirstMenuChoice() // prints the main menu and returns user selection

+static boolean applyOperation(int menuChoice, Elevator 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions