Question: 2 . Elevator 2 0 points Overview Imagine that a building with several floors has two elevators servicing floor requests ( people pushing the elevator

2. Elevator 20 points
Overview
Imagine that a building with several floors has two elevators servicing floor requests (people pushing the elevator button). In this assignment, you will write a program that simulates which elevator services each requested floor.
Task
We provide a zip file (find it in Autolab) that contains Elevator.java.
UPDATE and SUBMIT the corresponding file.
Programming
Write a program, Elevator.java, that reads 4 integer arguments from the command line:
the number of floors in the building at args[0]
the floor requests at args[1]
number of restricted floors at args[2]
and an optional passcode at args[3]
The program is expected to print which elevator services each request and which are the floors at which the elevators stopped at.
The number of floors () will always be greater than or equal to any value present in the floor requests ().args[0]args[1]
There will always be 2 elevators that start at floor 1.
The elevator that services a request will be based on which elevator is closer to the next floor in the floor requests.
The elevators traverse the floors with Elevator 1 taking priority over Elevator 2.
If the floor the elevators on are equal to each other, Elevator 1 will move to the requested floor.
Note that the floor requests has several floors and they are in reversed order. For example, for a building with 5 floors the requests could be 134.
The first request is floor 4. Since both elevators start at floor 1, and both elevators are in floor 1, elevator 1 will service this request.
The second request is floor 3. At this point elevator 1 is at floor 4 and elevator 2 is at floor 1, so elevator 1 is closer and will service this request.
The third request is floor 1. At this point elevator 1 is at floor 3 and elevator 2 is at floor 1, so elevator 2 is closer and will service this request.
HINT: note that you can use the modulus (%) operator to extract the rightmost digit, which is the first request. Then remove that request from the number by dividing the floor requests by 10(it removes the last digit).
The number of restricted floors, say n, represents the idea that the top n floors are restricted access.
The password argument () is optional, meaning that the argument is only read if someone is trying to access a restricted floor. Access to the floor is granted if: args[3]
The password modulus the number of floors is equal to the floor being requested, OR
The password modulus the number of floors is equal to zero AND requested floor is the topmost floor.
Assumptions
There will always be 2 elevators that traverse the floors with Elevator 1 taking priority over Elevator 2.
If the floor the elevators on are equal to each other, Elevator 1 will move to the requested floor.
The number of floors () will always be less than or equal to any value present in the queue of floor requests (args[0]args[1])
Output
The output is expected to be the elevator number (1 or 2) followed by the requested floor number. If there are any restricted floors in the requests, your output must include the status: Granted if the passcode is valid, Denied otherwise.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!