Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

elevator problem

807588Feb 25 2009 — edited Feb 25 2009
A tall office building contains 22 lifts. Each lifts starts out on the 1st floor. When a button next to the left door on a particular floor is pressed, then the building sends the nearest lift (in terms on distance) to that floor. The lift then travels to the required floor and stays there until summoned again by the building. To simplify matters the lifts move one at a time.

Two Classes are required
Building – this represents the building itself. It must have a member variable to represent the number of floors.

Lifts this represents a single lift. It must have a member variable to represent the current position of the lift.
It takes a lift 2 seconds to move up or down a single floor plus 5 seconds to get started and slow down again. Thus to move ten floors it takes
(10*2) + 5 = 25 seconds

Write these classes such that building has 2 lifts aggregated inside it. The building class will thus be responsible for the creation of each lift (in its own constructor). Write a member function of Building that takes a start and destination floor number and moves one of the aggregated lift objects ( the method should choose the lift nearest to the start floor if both lifts are the same distance away, choose either) to the destination floor. The method also returns the waiting time in other words the time taken for a lift to reach the start floor. We are not concerned by the time taken for the remainder of the user’s journey but the lift should end up on the destination floor.
Write a main method that creates a building and then attempts to find the average waiting time for a lift, by repeatedly calling a lift to a random floor (I suggest 1000 calls give a good idea) and making it travel to a second random destination floor. You will need to write a while loop to do this as well as use the random () in java API.
Imagine that the lifts were not made by same manufacturer and that they have a second member variable, efficiency, that acted as a modifier t the time taken to move between floors ( e.g. an efficiency of 0.5 meant it took half the time.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 25 2009
Added on Feb 25 2009
2 comments
258 views