I have a very similar situation to what Norm discussed with this student last year.
I am making a elevator simulator for my class. It needs to be "event time". I am having trouble understanding how I can make an "event time" simulator. Initially I was using a while loop to run a clock time simulation of x seconds for each event, until I ran into a concrete wall and had to call another method which took X seconds, while still needing to execute code.
An example of what I did is:
Spawn person -> person.goToElevator (Takes x seconds) - > person.waitForElevator (Until elevator arrives, x seconds). While this is happening, I needed to create another person and do the same thing, this will add another to the queue if the first person is still waiting. Etc etc, you get the point.
We have not learnt about multi threading, that is the next assignment.
Here is a quote from my lecturer:
"That's right, it requires multi-threading which we're not doing in this paper. Here's a solution that can work:
The person waiting for the lift and then doing lots of other things should do all that in a fraction of a second. So, you don't let the person really wait. Instead, you will set a timestamp in the future in the person object that "he's busy till that time". In all other steps in your simulation you will first check if a person is "busy" (i.e. has a timestamp in the future). If so, you can't use this object, otherwise, you can.
Can you use that?"
I half understand this.. Is anyone in anyway able to provide me with a tiny snippet of code to show me an example of how to go about creating this? I can't wrap my head around it simulating all this in a fraction of a second... How does it create a bigger queue? Etc etc..
Outputs I would have in my final simulation would be, averageQueueLength, numOfPeopleInBuilding etc.
Any help would be great.