Question: Write a program, Elevator.java, that reads 4 integer arguments from the command line: the number of floors in the building at args [ 0 ]
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 args will always be greater than or equal to any value present in the floor requests args
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 args 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:
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.
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
