From 630d479739a382e02191e7328389804f41643f73 Mon Sep 17 00:00:00 2001 From: JISAUAY Date: Thu, 10 Oct 2024 15:02:24 -0500 Subject: [PATCH] added readme and comments for assignment --- readme.txt | 32 ++++++++++++++++++++++++++++++++ src/BridgeSimulator.java | 7 +++++++ src/Car.java | 7 +++++++ src/EmergencyVehicle.java | 7 +++++++ src/TrafficController.java | 7 +++++++ src/Truck.java | 7 +++++++ src/Vehicle.java | 9 ++++++++- 7 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 readme.txt diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..af5227e --- /dev/null +++ b/readme.txt @@ -0,0 +1,32 @@ +# About + +This is a program that simulates traffic on a single lane bridge. All vehicles that cross the bridge implement the abstract class Vehicle. The traffic controller class manages the Semaphores and which Vehicles get to cross at what times. There's also some code in there for adding cars to the simulation. Emergency vehicles are randomly scheduled to appear at certain times during the simulation based off of the arguments. + +After the program is done running it will output some information about what happened during the run of the program and some logs. The program uses Semaphores to handle what vehicle should go next, and seeing if there is a vehicle on the bridge. The vehicle class implements the runnable class and is run in a new thread when crossing the bridge for some amount of time based on the implementations. + +There is a semaphore for each direction, the bridge, and emergencies. + +# Compile + +To compile the program you must change your directory to `src/`. You may run the following commands to compile the program. + +```sh +cd src +javac *.java +``` + +# Running + +To run the program you may run the following commands + +```sh +java BridgeSimulator +``` + +or + +```sh +java BridgeSimulator (simulation time) (emergencies) +``` + +If no command line arguments are given the program will default to a simulation time of 30 seconds and 2 emergencies. \ No newline at end of file diff --git a/src/BridgeSimulator.java b/src/BridgeSimulator.java index 592f048..53f04f2 100644 --- a/src/BridgeSimulator.java +++ b/src/BridgeSimulator.java @@ -1,3 +1,10 @@ +/* + * Bridge Simulator : Operating Systems + * + * Program by Jackson Dean Hodge + * Student ID: 010955002 + * */ + import java.util.*; public class BridgeSimulator { diff --git a/src/Car.java b/src/Car.java index 9070732..4d957cc 100644 --- a/src/Car.java +++ b/src/Car.java @@ -1,3 +1,10 @@ +/* + * Bridge Simulator : Operating Systems + * + * Program by Jackson Dean Hodge + * Student ID: 010955002 + * */ + public class Car extends Vehicle { public int crossingTime = 2; public static int priority = 2; diff --git a/src/EmergencyVehicle.java b/src/EmergencyVehicle.java index becc9ce..b80e003 100644 --- a/src/EmergencyVehicle.java +++ b/src/EmergencyVehicle.java @@ -1,3 +1,10 @@ +/* + * Bridge Simulator : Operating Systems + * + * Program by Jackson Dean Hodge + * Student ID: 010955002 + * */ + public class EmergencyVehicle extends Vehicle { public int crossingTime = 1; public static int priority = 1; diff --git a/src/TrafficController.java b/src/TrafficController.java index 03da35a..a80070b 100644 --- a/src/TrafficController.java +++ b/src/TrafficController.java @@ -1,3 +1,10 @@ +/* +* Bridge Simulator : Operating Systems +* +* Program by Jackson Dean Hodge +* Student ID: 010955002 +* */ + import java.util.*; import java.util.concurrent.Semaphore; diff --git a/src/Truck.java b/src/Truck.java index 91256a7..0b8479b 100644 --- a/src/Truck.java +++ b/src/Truck.java @@ -1,3 +1,10 @@ +/* + * Bridge Simulator : Operating Systems + * + * Program by Jackson Dean Hodge + * Student ID: 010955002 + * */ + public class Truck extends Vehicle { public int crossingTime = 3; public static int priority = 2; diff --git a/src/Vehicle.java b/src/Vehicle.java index a395a63..d2c5b3c 100644 --- a/src/Vehicle.java +++ b/src/Vehicle.java @@ -1,3 +1,10 @@ +/* + * Bridge Simulator : Operating Systems + * + * Program by Jackson Dean Hodge + * Student ID: 010955002 + * */ + import java.util.Random; import java.util.concurrent.Semaphore; @@ -56,7 +63,7 @@ public abstract class Vehicle implements Runnable { @Override public void run() { try { - Thread.sleep(this.crossingTime); + Thread.sleep(this.getCrossingTime()); hasRun = true; } catch (InterruptedException e) { e.printStackTrace();