Skip to content

Nirmit2103/Vehicle-Management-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš— Vehicle Management System

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.

πŸ“‹ Table of Contents

✨ Features

Highway Simulator (GUI Mode)

  • 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

Fleet Management System (CLI Mode)

  • Complete fleet management operations
  • Vehicle maintenance tracking
  • Fuel consumption monitoring
  • Passenger and cargo management

πŸ“ Project Structure

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

πŸ”§ Prerequisites

  • Java Development Kit (JDK): Version 8 or higher
  • Java Runtime Environment (JRE): Version 8 or higher
  • Operating System: Windows, macOS, or Linux

πŸ’Ώ Installation

  1. Clone the repository:

    git clone https://github.com/Nirmit2103/Vehicle-Management-system.git
    cd Vehicle-Management-system
  2. Navigate to the source directory:

    cd src
  3. Compile all Java files:

    javac *.java

    Or compile with all subdirectories:

    javac -d . *.java exceptions/*.java fleet/*.java interfaces/*.java vehicles/*.java

πŸš€ How to Run

Option 1: Highway Simulator (GUI Mode - Recommended)

Run the multithreaded GUI simulator:

java Main

What 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

Option 2: Fleet Management System (CLI Mode)

Run the command-line interface:

java MainCLI

What happens:

  • Opens an interactive command-line menu
  • Allows full fleet management operations
  • Manage vehicles, fuel, maintenance, and more

πŸ“– Usage Guide

Highway Simulator GUI

  1. Start Simulation:

    • Click "▢️ Start Simulation" to begin
    • Watch vehicles move and consume fuel in real-time
  2. 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
  3. Fix Race Condition:

    • Select "Synchronized (Fixed)" mode
    • Start simulation
    • Both counters will stay synchronized (exact match when stopped)
  4. 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
  5. Export Logs:

    • Click "πŸ’Ύ Export Log"
    • Creates simulation_log_YYYYMMDD_HHMMSS.txt with all events
  6. Reset:

    • Click "πŸ”„ Reset Simulation" to reload vehicles and clear statistics

CLI Fleet Management

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

βš™οΈ Configuration

Customizing Highway Vehicles

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:

  • Car
  • Truck
  • Bus

Fleet Data

The CLI mode uses fleetdata.csv to persist fleet information.

πŸ—οΈ Architecture

Design Patterns

  • Worker Thread Pattern: Each VehicleWorker encapsulates a vehicle thread
  • Observer Pattern: GUI observes and displays vehicle states
  • Facade Pattern: HighwaySimulator provides simple interface to complex system
  • Strategy Pattern: Different synchronization strategies (synchronized vs unsynchronized)

Multithreading Architecture

  • 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

Object-Oriented Principles

  • 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

πŸ‘¨β€πŸ’» Author

Nirmit Jain (Student ID: 2024388)
AP-M2025 - Assignment 3: Fleet Highway Simulator

πŸ“ License

This project is part of an academic assignment. Please respect academic integrity policies.

πŸ› Troubleshooting

Common Issues

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.

🎯 Testing the Simulation

Test 1: Basic Race Condition

  1. Run java Main
  2. Select "Unsynchronized (Race Condition)" mode
  3. Start simulation
  4. Observe 10-20% discrepancy between counters (RED highlight in log)

Test 2: Synchronization Fix

  1. Select "Synchronized (Fixed)" mode
  2. Start simulation
  3. Stop simulation
  4. Verify Highway Distance = Total Individual Mileage (exact match)

Test 3: Control Tests

  1. Test pause/resume functionality for all vehicles
  2. Test pause/resume for individual vehicles
  3. Test manual refuel for selected vehicle

Test 4: Auto-Refuel

  1. Enable "Auto-Refuel" checkbox
  2. Wait for a vehicle to run out of fuel
  3. Verify automatic refuel and continuation

Happy Driving! πŸš—πŸ’¨

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages