Question: ================================================================================== 1. Introduction We want to write a program to simulate the behavior of a self-serve gas station. The goal of this simulation is to
==================================================================================
1. 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
stations 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.
2. Assumptions and Requirements
2.1. 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 completing service and departing
a car leaving the waiting line, advancing to a pump and
beginning service
2.2. The limits of simulations parameters
- Maximum number of pumps 10
- Maximum simulation length 10000
- Maximum service duration 500
- Maximum car queue limit 50
- Probability of a new car 1% - 100%
2.3. Input parameters and car (random/file) data
- The following data are read at the beginning of the simulation:
int numGasPumps; // number of gas pumps.
int simulationTime; // time to run simulation
int carQSizeLimit; // car queue size limit
int chancesOfArrival; // probability of a new car (1 - 100)
int maxDuration; // maximum service (or pumping gas) duration per car
int dataSource; // data source: from file or random
- Sample input layout :
$ java PJ3.GasStationSimulation
*** Get Simulation Parameters ***
Enter simulation time (positive integer) : 10
Enter the number of gas pumps : 3
Enter maximum service time of cars : 5
Enter chances (0% < & <= 100%) of new car : 75
Enter car queue size limit : 2
Enter 1/0 to get data from file/rand() : 1 <-- see more details below
Enter filename : DataFile <-- for input 1 above
- In each time unit of simulation, your program will need two positive integers
numbers to compute (i) boolean anyNewArrival & (ii) int serviceDuration.
A user should have two options (1 or 0) 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. In each time unit, anyNewArrival & serviceDuration are computed
in getCarData() as follows :
read data1 and data2 from the file;
anyNewArrival = (((data1%100)+1)<= chancesOfArrival);
serviceDuration= (data2%maxDuration)+1;
For user input 0, numbers are generated by method nextInt() in a Random
object, dataRandom, which should be constructed at the beginning of
simulation. In each time unit, anyNewArrival & serviceDuration are computed
in getCarData() as follows :
anyNewArrival = ((dataRandom.nextInt(100)+1) <= chancesOfArrival);
serviceDuration = dataRandom.nextInt(maxDuration)+1;
2.4. Input/Output information
- At the end of each time unit, you program should print out "snap-shot" of
simulation. At the end of simulation, you program need to print out end
of simulation report
- Sample run is provided at the end of Readme file.
2.5. Data structures and simulation algorithm
- I have defined package PJ3 with the Car, GasPump and GasStation classes,
you need to implement their methods. I also provide an outline of a
simulation program GasStationSimulation.java.
3. Compile and run program
- PJ3.zip files are all available on this google drive ( accessible to anyone ) :-
https://drive.google.com/open?id=1TRslmOnFLN2sLD_df_kogCrpCNf0rdJD
- Compile programs (you are in directory containing Readme file):
javac PJ3/*.java
- Run programs (you are in directory containing Readme file):
// Run simulation
java PJ3.GasStationSimulation
4. Submission
- To submit your project, you need to zip all source files (*.java) into PJ3.zip
and upload PJ3.zip file to ilearn.
=====================================================================================
SAMPLE RUN
=====================================================================================
$ ls
DataFile PJ3 Readme
$ javac PJ3/*.java
$ java PJ3.Car
Car Info:CarID=1:ServiceDuration=30:ArrivalTime=40
$ java PJ3.GasPump
CarID=1:ServiceDuration=5:ArrivalTime=15
GasPumpID:5:startIntervalTime=0:endIntervalTime=0:total free time=0:total service time=0:Car:null
Start service car:
GasPumpID:5:startIntervalTime=20:endIntervalTime=25:total free time=20:total service time=0:Car:CarID=1:ServiceDuration=5:ArrivalTime=15
End service car:
GasPumpID:5:startIntervalTime=25:endIntervalTime=25:total free time=20:total service time=5:Car:CarID=1:ServiceDuration=5:ArrivalTime=15
Gas pump statistics data:
GasPump ID : 5
Total free time : 20
Total service time : 5
Total # of cars : 1
Average service time : 5.00
$ java PJ3.GasStation
[CarID=1:ServiceDuration=18:ArrivalTime=10, CarID=2:ServiceDuration=33:ArrivalTime=11, CarID=3:ServiceDuration=21:ArrivalTime=12, CarID=3:ServiceDuration=37:ArrivalTime=13]
===============================================
Remove car:CarID=1:ServiceDuration=18:ArrivalTime=10
Remove car:CarID=2:ServiceDuration=33:ArrivalTime=11
Remove car:CarID=3:ServiceDuration=21:ArrivalTime=12
Remove car:CarID=3:ServiceDuration=37:ArrivalTime=13
===============================================
freeGasPumpQ:[GasPumpID:1:startIntervalTime=0:endIntervalTime=0:total free time=0:total service time=0:Car:null, GasPumpID:2:startIntervalTime=0:endIntervalTime=0:total free time=0:total service time=0:Car:null, GasPumpID:3:startIntervalTime=0:endIntervalTime=0:total free time=0:total service time=0:Car:null, GasPumpID:4:startIntervalTime=0:endIntervalTime=0:total free time=0:total service time=0:Car:null]
===============================================
Remove free gas pump:GasPumpID:1:startIntervalTime=0:endIntervalTime=0:total free time=0:total service time=0:Car:null
Remove free gas pump:GasPumpID:2:startIntervalTime=0:endIntervalTime=0:total free time=0:total service time=0:Car:null
Remove free gas pump:GasPumpID:3:startIntervalTime=0:endIntervalTime=0:total free time=0:total service time=0:Car:null
Remove free gas pump:GasPumpID:4:startIntervalTime=0:endIntervalTime=0:total free time=0:total service time=0:Car:null
===============================================
freeGasPumpQ:[]
busyGasPumpQ:[]
===============================================
Assign cars to gas pumps
===============================================
Insert busy gas pumps to busy Q
busyGasPumpQ:[GasPumpID:1:startIntervalTime=13:endIntervalTime=31:total free time=13:total service time=0:Car:CarID=1:ServiceDuration=18:ArrivalTime=10, GasPumpID:2:startIntervalTime=13:endIntervalTime=46:total free time=13:total service time=0:Car:CarID=2:ServiceDuration=33:ArrivalTime=11, GasPumpID:3:startIntervalTime=13:endIntervalTime=34:total free time=13:total service time=0:Car:CarID=3:ServiceDuration=21:ArrivalTime=12, GasPumpID:4:startIntervalTime=13:endIntervalTime=50:total free time=13:total service time=0:Car:CarID=3:ServiceDuration=37:ArrivalTime=13]
===============================================
Remove busy gas pumps from busy Q
Remove busy gas pump:GasPumpID:1:startIntervalTime=31:endIntervalTime=31:total free time=13:total service time=18:Car:CarID=1:ServiceDuration=18:ArrivalTime=10
Remove busy gas pump:GasPumpID:3:startIntervalTime=34:endIntervalTime=34:total free time=13:total service time=21:Car:CarID=3:ServiceDuration=21:ArrivalTime=12
Remove busy gas pump:GasPumpID:2:startIntervalTime=46:endIntervalTime=46:total free time=13:total service time=33:Car:CarID=2:ServiceDuration=33:ArrivalTime=11
Remove busy gas pump:GasPumpID:4:startIntervalTime=50:endIntervalTime=50:total free time=13:total service time=37:Car:CarID=3:ServiceDuration=37:ArrivalTime=13
$ java PJ3.GasStationSimulation
*** Get Simulation Parameters ***
Enter simulation time (positive integer) : 10
Enter the number of gas pumps : 3
Enter chances (0% < & <= 100%) of new car : 75
Enter maximum service time of cars : 5
Enter car queue size limit : 2
Enter 0/1 to get data from Random/file : 1
Enter filename : DataFile
*** Start Simulation ***
Gas Pump #1 to #3 are ready...
---------------------------------------------
Time : 0
car #1 arrives with duration 5 units
car #1 wait in the car queue
car #1 gets a pump
pump #1 starts serving car #1 for 5 units
---------------------------------------------
Time : 1
car #2 arrives with duration 2 units
car #2 wait in the car queue
car #2 gets a pump
pump #2 starts serving car #2 for 2 units
---------------------------------------------
Time : 2
car #3 arrives with duration 5 units
car #3 wait in the car queue
car #3 gets a pump
pump #3 starts serving car #3 for 5 units
---------------------------------------------
Time : 3
No new car!
car #2 is done
pump #2 is free
---------------------------------------------
Time : 4
car #4 arrives with duration 3 units
car #4 wait in the car queue
car #4 gets a pump
pump #2 starts serving car #4 for 3 units
---------------------------------------------
Time : 5
No new car!
car #1 is done
pump #1 is free
---------------------------------------------
Time : 6
car #5 arrives with duration 3 units
car #5 wait in the car queue
car #5 gets a pump
pump #1 starts serving car #5 for 3 units
---------------------------------------------
Time : 7
car #6 arrives with duration 5 units
car #6 wait in the car queue
car #4 is done
pump #2 is free
car #3 is done
pump #3 is free
car #6 gets a pump
pump #2 starts serving car #6 for 5 units
---------------------------------------------
Time : 8
No new car!
---------------------------------------------
Time : 9
No new car!
car #5 is done
pump #1 is free
============================================
End of simulation report
# total arrival cars : 6
# cars gone-away : 0
# cars served : 6
*** Current GasPumps Info. ***
# waiting cars : 0
# busy gas pumps : 1
# free gas pumps : 2
Total waiting time : 0
Average waiting time : 0.00
Busy GasPumps Info. :
GasPump ID : 2
Total free time : 2
Total service time : 8
Total # of cars : 3
Average service time : 2.67
Free GasPumps Info. :
GasPump ID : 3
Total free time : 5
Total service time : 5
Total # of cars : 1
Average service time : 5.00
GasPump ID : 1
Total free time : 2
Total service time : 8
Total # of cars : 2
Average service time : 4.00
NOTE:- I have attached the datafile location photo describing the exact location the java program should access the binary datafile and compile.
NOTE:- All the required files are in the PJ3 folder on the given google drive link: -
https://drive.google.com/open?id=1TRslmOnFLN2sLD_df_kogCrpCNf0rdJD
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
