Introduction

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 and Requirements

Assumptions

  • At most one car arrival per time unit
  • All numbers are positive integer numbers (>=0), except average values should be displayed to two decimal places
  • No time lost in between events:
    • a car arriving and entering waiting line
    • a car arriving and leaving without pumping gas
    • a car leaving the waiting line, advancing to a pump and beginning service
    • a car completing service and departing
  • The limits of simulations parameters:
    • Maximum number of pumps 50
    • Maximum simulation length 10000
    • Maximum service time 500
    • Maximum car queue limit 50
    • Probability of a new car 1% - 100%

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

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.