This project involved simulating lines representing queues at grocery stores and such. A customer would appear, choose a line (taking a certain amount of time to do so), and join it, then wait until it was at the end to have its items decremented. After all its items were gone, it would leave the line.
This project did not really have the usual "tasks", and was instead just a general guide with hints on how to build the project. This made it very different and more challenging than most previous projects. I will attempt to explain how I organized my code instead.
My lowest class was the customer, which was drawn as a circle. In the constructor, I checked which strategy integer was passed in as a parameter, and set up a waiting time for each kind. This would be used in update state, which is where I tell the customer how to choose a line, then add it to that line and associate them. Every iteration of the simulation, this update would be called, so the time to wait to get in line would be decremented.
I made a checkout class next, which represented the queue system that the customers would wait in. Once inside a queue, a customer would passively update as a part of it. In the line's update state, it checks if it has customers. If it does, it will decrement the amount of items of the one in front, given they have above 0. If they have 0, the customer will be removed from the overall arraylist of customers as well as the line itself. There was also a method to initially add the customer to the line, which would set the x and y of the customers; the y would depend on the queue's current length, of course.
The next class, as usual, was the landscape, which contained both lines and newly-spawned customers. It had an overall method to update everything, and also a method to add customers. It created some customers and the queues to start, as well. Note that I didn't use a spawn class, instead having a method to add customers in the landscape class. The landscape would be created in the simulation top-level class, along with a landscape display class, like always. The landscape display is based on all of the past ones, and updated to handle this project's classes.
In my simulation class, I had my main loop have an integer representing the strategy for customers to join lines, and changed it there if I needed to. If the timestep was over 0 (because some are already there to start with), it would create more customers. Then, I would repaint and sleep to show that customers are there before they switch into line and never get shown spawning first. I updated all customers after that, and then the lines.
For the last task, it said to find the mean and standard deviation. For this, I created various methods in landscape that took the list of all of the times to get out of line for each customer, then did things like counting them, totaling them and dividing by the number of customers, getting a list of the distances of each from the mean leaving-time, square rooting that, etc. I had the stats print out about every 100 customers, which I checked in a method in landscape that checked the amount of finished customers, and had them print if the number was close to a multiple of 100. My results seemed to be mathematically incorrect, because they were increasing the more customers checked out, but nevertheless, I can discuss the results.
It seemed that choosing randomly was inefficient.