Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

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.

strat 1

strat 4

strat 5

  • No labels