We want to write a program to simulate the behavior of a self-serve gas station. The goal of this simulation is to collect statistical information of the gas station’s cars and gas pumps. A gas station consists of several pumps and a car waiting line (i.e. a car queue). In each time unit, at most one new car arrives at the gas station. If the car waiting line is too long, the car leaves without getting gas; otherwise, the car gets into the waiting line. If all pumps are busy, cars in the waiting lines must wait for a gas pump. If a pump is free and cars are waiting, the first car in the waiting line gets the pump and begins pumping gas immediately. When a car finishes using a pump, the car departs and the pump becomes free. We will run the simulation through many units of time. At the end of each time unit, your program should print out a "snap-shot" of queues, cars and pumps. At the end of the program, your program should print out statistics and conclude simulation.
Assumptions
Input parameters and customer (random/file) data: The following data are read at the beginning of the simulation : See image.
Sample input layout : See image.
In each time unit of simulation, your program will need two positive integer numbers to compute boolean anyNewArrival & intserviceTime. A user should have two options to specify the source of those numbers:
For user input 1, numbers are read from a file. A filename should be provided at the beginning of simulation. Each line in a datafile should contain two positive numbers (> 0). A datafile should contain sufficient data for simulationTime up to 500 units, i.e. at least 500 lines. In each time unit, anyNewArrival & serviceTime are generated as follows :
read data1 and data2 from the file;
anyNewArrival = (((data1%100)+1)<= chancesOfArrival);
serviceTime = (data2%maxServiceTime)+1;
For user input 0, numbers are generated by by method nextInt() in a Random object, dataRandom. dataRandom should be constructed at the beginning of simulation. In each time unit, anyNewArrival & serviceTime are generated as follows:
anyNewArrival = ((dataRandom.nextInt(100)+1) <= chancesOfArrival);
serviceTime = dataRandom.nextInt(maxServiceTime)+1;
Output Information: At the end of each time unit, you program should print out information as the following example : See image.
At the end of simulation, you need to print out information as the following example : See image.
Data Structures and simulation algorithm: I have defined the Car, GasPump and GasStation classes, you need to implement their functions. I also provide an outline of my program GasStationSimulator.java. You need to download PJ3.jar file