Question: 2 . Elevator 2 0 points Overview Imagine that a building with several floors has two elevators servicing floor requests ( people pushing the elevator
Elevator 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 integer arguments from the command line:
the number of floors in the building at args
the floor requests at args
number of restricted floors at args
and an optional passcode at args
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 argsargs
There will always be elevators that start at floor
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 taking priority over Elevator
If the floor the elevators on are equal to each other, Elevator 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 floors the requests could be
The first request is floor Since both elevators start at floor and both elevators are in floor elevator will service this request.
The second request is floor At this point elevator is at floor and elevator is at floor so elevator is closer and will service this request.
The third request is floor At this point elevator is at floor and elevator is at floor so elevator 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 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
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 elevators that traverse the floors with Elevator taking priority over Elevator
If the floor the elevators on are equal to each other, Elevator 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 argsargs
Output
The output is expected to be the elevator number or 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
