So I need to make an elevator simulator, and I was wondering how can I go about continuously generating people to call the elevator. I need this to go on forever. So basically a person is created and calls the elevator. All of these calls are kept track of but I think I need to keep track of the people who are actually on the elevator too.
I have a few classes Person
, Elevator
, ElevatorCall
& ElevatorCallQueue
.
In Person I have a
run()
method which basically makes an Elevator call with the current floor and destination floor and then I have aBlockingQueue
that I put the call on. This run method just runs while true.In
ElevatorCall
I just have getters and setters for the collection and destination floorsIn ElevatorCallQueue, I have variables for MAX_CALLS and numberOfPeople. I have a
BlockingQueue<ElevatorCall> queue = new ArrayBlockingQueue<ElevatorCall>(MAX_CALLS)
and aList<Person>
I add people to the list and I run through the list and start therun()
method on each person. Finally I create an elevator and provide the queue, and run it.In Elevator I have the
BlockingQueue<ElevatorCalls>
. I have awhile(true
) here also, and inside it I make anArrayList<ElevatorCall>
and then I use the BlockingQueues drainTo method using theArrayList<ElevatorCalls>
as a parameter. The rest of therun()
method basically iterates through the array list and does what an elevator does, so It goes to the first pressed button, checks each floor for people and if it is a destination floor.
Right now I've gotton stuck and dont know where to go from here. I need to some how have People continiously added and calling the elevator, and have the Elevator wait if there is no more calls. Would appreciate it if anybody could help put me in the right direction. Thanks
EDIT
Here is the code to the elevator class as somebody said I should post some code. However I'm not sure what code to post so I thought I'd just put in the entire class