Java Gas Station Simulator

    While it wouldn't make a very fun video game, my Gas Station Simulator 2020 is a neat way to practice concurrency in Java. It simulates up to 25 cars arriving, filling their tanks at 12 different pumps, and leaving at different times. It runs through 3 different scenarios, each one testing a different amount of cars that want different kinds of gas. In order to accommodate the cars as they come, we use singletons to ensure only one car can use a pump at a time, and that pump can only be used by one car. 

    Much of the code is there to manage the different states someone can be in while pumping gas (pumping, paying, getting a receipt, etc.). The most challenging thing about this project was managing the sometimes confusing errors that can occur from a concurrent program. Sometimes a car would appear multiple times, or not appear at all. Until we correctly assigned the cars to a pump, all our cars only seemed to use two of the twelve pumps, but once we placed a sleep in the correct place and got the synchronized values just right, it all worked out!

    You can check out the code here!

Comments

Popular posts from this blog

API's in C#

Using WebRTC to build a videophone in React and TypeScript

Reviewing WPF and MVVM