A comprehensive Java-based vehicle fleet management system with multithreading capabilities and both GUI and CLI interfaces. This project demonstrates object-oriented programming, multithreading, synchronization, and Java Swing GUI development.
- Features
- Project Structure
- Prerequisites
- Installation
- How to Run
- Usage Guide
- Configuration
- Architecture
- Author
- Multithreaded Vehicle Simulation: Each vehicle runs in its own thread
- Race Condition Demonstration: Toggle between synchronized and unsynchronized modes
- Real-time Monitoring: Visual dashboard showing vehicle status, fuel levels, and mileage
- Vehicle Control:
- Start/Stop simulation
- Pause/Resume all vehicles or individual vehicles
- Manual and auto-refuel capabilities
- Reset simulation
- Data Export: Export simulation logs with timestamps
- Custom Vehicles: Load vehicles from configuration file
- Complete fleet management operations
- Vehicle maintenance tracking
- Fuel consumption monitoring
- Passenger and cargo management
src/
βββ Main.java # GUI entry point
βββ MainCLI.java # CLI entry point
βββ HighwaySimulator.java # Main GUI simulation controller
βββ FleetCLI.java # CLI interface
βββ fleetdata.csv # Fleet data storage
βββ highway_vehicles.txt # Vehicle configuration for simulator
βββ exceptions/ # Custom exception classes
β βββ InsufficientFuelException.java
β βββ InvalidOperationException.java
β βββ OverloadException.java
βββ fleet/ # Fleet management
β βββ FleetManager.java
βββ interfaces/ # Interface definitions
β βββ CargoCarrier.java
β βββ FuelConsumable.java
β βββ Maintainable.java
β βββ PassengerCarrier.java
βββ vehicles/ # Vehicle class hierarchy
βββ Vehicle.java # Base class
βββ LandVehicle.java
βββ AirVehicle.java
βββ WaterVehicle.java
βββ Car.java
βββ Truck.java
βββ Bus.java
βββ Airplane.java
βββ CargoShip.java
- Java Development Kit (JDK): Version 8 or higher
- Java Runtime Environment (JRE): Version 8 or higher
- Operating System: Windows, macOS, or Linux
-
Clone the repository:
git clone https://github.com/Nirmit2103/Vehicle-Management-system.git cd Vehicle-Management-system -
Navigate to the source directory:
cd src -
Compile all Java files:
javac *.javaOr compile with all subdirectories:
javac -d . *.java exceptions/*.java fleet/*.java interfaces/*.java vehicles/*.java
Run the multithreaded GUI simulator:
java MainWhat happens:
- Opens a graphical interface showing the highway simulation
- Vehicles are loaded from
highway_vehicles.txt - You can control the simulation, monitor vehicles, and observe race conditions
Run the command-line interface:
java MainCLIWhat happens:
- Opens an interactive command-line menu
- Allows full fleet management operations
- Manage vehicles, fuel, maintenance, and more
-
Start Simulation:
- Click "
βΆοΈ Start Simulation" to begin - Watch vehicles move and consume fuel in real-time
- Click "
-
Demonstrate Race Condition:
- Select "Unsynchronized (Race Condition)" mode
- Start simulation
- Observe the discrepancy between "Highway Distance" and "Total Individual Mileage"
- This shows lost updates due to concurrent access
-
Fix Race Condition:
- Select "Synchronized (Fixed)" mode
- Start simulation
- Both counters will stay synchronized (exact match when stopped)
-
Vehicle Controls:
- Pause/Resume All: Control all vehicles simultaneously
- Pause/Resume Selected: Control individual vehicles via dropdown
- Refuel Selected: Manually add 20L fuel to a selected vehicle
- Auto-Refuel: Check the box to automatically refuel vehicles when empty
-
Export Logs:
- Click "πΎ Export Log"
- Creates
simulation_log_YYYYMMDD_HHMMSS.txtwith all events
-
Reset:
- Click "π Reset Simulation" to reload vehicles and clear statistics
Follow the on-screen menu to:
- Add/Remove vehicles from fleet
- Perform maintenance operations
- Manage fuel consumption
- Load/Unload passengers and cargo
- View fleet statistics
Edit highway_vehicles.txt to add or modify vehicles:
Format:
VehicleType,ID,Model,MaxSpeed,FuelToAdd
Example:
Car,CAR-01,Tesla Model S,210,60
Truck,TRK-01,Volvo FH16,140,200
Bus,BUS-01,Mercedes Citaro,120,180
Supported Vehicle Types:
CarTruckBus
The CLI mode uses fleetdata.csv to persist fleet information.
- Worker Thread Pattern: Each
VehicleWorkerencapsulates a vehicle thread - Observer Pattern: GUI observes and displays vehicle states
- Facade Pattern:
HighwaySimulatorprovides simple interface to complex system - Strategy Pattern: Different synchronization strategies (synchronized vs unsynchronized)
- Each vehicle runs in its own worker thread
- All threads share a common counter (
highwayDistance) - GUI runs on the Event Dispatch Thread (EDT)
- Thread communication via
wait()/notify()for pause/resume
- Inheritance: Vehicle hierarchy with specialized types
- Polymorphism: Common interface for all vehicle types
- Encapsulation: Protected vehicle state with controlled access
- Abstraction: Interface-based design for capabilities
Nirmit Jain (Student ID: 2024388)
AP-M2025 - Assignment 3: Fleet Highway Simulator
This project is part of an academic assignment. Please respect academic integrity policies.
Issue: javac: command not found
Solution: Ensure Java JDK is installed and added to your PATH environment variable.
Issue: GUI doesn't open
Solution: Ensure you have a display environment (not running in headless mode).
Issue: Vehicles not loading
Solution: Verify highway_vehicles.txt exists in the src directory and is properly formatted.
Issue: Compilation errors
Solution: Make sure all subdirectories are compiled. Use the full compilation command provided above.
- Run
java Main - Select "Unsynchronized (Race Condition)" mode
- Start simulation
- Observe 10-20% discrepancy between counters (RED highlight in log)
- Select "Synchronized (Fixed)" mode
- Start simulation
- Stop simulation
- Verify Highway Distance = Total Individual Mileage (exact match)
- Test pause/resume functionality for all vehicles
- Test pause/resume for individual vehicles
- Test manual refuel for selected vehicle
- Enable "Auto-Refuel" checkbox
- Wait for a vehicle to run out of fuel
- Verify automatic refuel and continuation
Happy Driving! ππ¨