Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚉 Bangladesh Train Tracker

Java Swing Course

Bangladesh Train Tracker is a graphical train-tracking application that allows users to select a train and view its route information, schedule, current progress, next station, remaining distance and operating day


✨ FEATURES

I. Train Selection

  • 🚉 Select a train from a dropdown menu
  • 🔎 Search trains using their train number/name
  • 📋 Display detailed information for the selected train
  • ⚡ Automatically update the interface whenever a different train is selected

Currently included trains:

Train No. Train Name Route
756 Madhumati Express Rajshahi → Dhaka
792 Banalata Express Chapainawabganj → Dhaka
754 Silkcity Express Rajshahi → Dhaka
760 Padma Express Rajshahi → Dhaka

II. Train Information

For the selected train, the application displays:

  1. 🚉 Train Number
  2. 🏷️ Train Name
  3. 🚉 Start Station
  4. 🕐 Time of Departure
  5. 🏁 Destination Station
  6. 🕐 Time of Arrival
  7. 🛑 Number of Stops
  8. 📍 Next Station
  9. 🚉 Next Stop
  10. 📏 Total Distance

The information is displayed dynamically on the right side of the application window


III. Train Progress Tracker

The application includes a custom graphical route tracker:

  • 🟢 Green stops → Stations already travelled
  • 🔴 Red stops → Stations yet to be travelled
  • 🟡 Yellow line → Approximate distance already travelled
  • 📊 Progress is calculated from the number of passed stops
  • 🚉 Every train has its own number of stations/stops

The tracker is implemented using a custom JPanel and Java's Graphics2D rendering system


IV. Remaining Journey Information

The application displays the remaining journey information for the selected train. For example: Remaining 126 km in 02:50 hours

This provides an approximate indication of:

  • 📏 Remaining distance
  • ⏱️ Remaining journey time

V. Train Off-Day Detection

The application automatically extracts the current day from the system and compares it with the train's scheduled off day. If the selected train is not operating on the current day: TRAIN OFF DAY: SUNDAY. The application also displays: Not Operating Today and resets the route progress tracker


VI. Persistent Data Storage

Train information is stored permanently in: train-data.txt

The application:

  • 📖 Reads train information from the file at startup
  • 💾 Creates default train data if the file does not exist
  • 📝 Saves train information back to the file
  • 🔄 Loads the saved information whenever the application starts

⚙️ TECHNOLOGIES USED

Category Technology Purpose
💻 Core Language Java Implements the complete application logic
🎨 GUI Framework Java Swing Creates the desktop graphical interface
🧩 OOP Classes & Objects Models trains and stations
🏛️ Abstraction Abstract Class Provides the RailwayEntity base class
🔌 Interface ITrainTracker Defines the UI update contract
🧬 Inheritance Train extends RailwayEntity Demonstrates class inheritance
🗂️ Collections ArrayList Stores train stations
🗺️ Collections HashMap Stores and retrieves train objects
📁 File Handling FileReader, FileWriter Reads/writes train-data.txt
📖 Buffered I/O BufferedReader, PrintWriter Efficient file reading/writing
📅 Date Handling LocalDate Extracts the current system date/day
🕐 Date Formatting TextStyle, Locale Converts system day into readable form
🎨 Graphics Graphics2D Draws the train progress tracker
🖼️ Image Handling ImageIcon Loads government and railway logos
⚠️ Error Handling try-catch Handles file and data-processing errors

🧩 OBJECT-ORIENTED DESIGN

The project was designed using multiple OOP concepts as required by the assignment.

1. RailwayEntity - Abstract Class

abstract class RailwayEntity - The abstract class contains common railway entity information and defines: public abstract String getEntityType();. The Train class inherits from this class.

2. Station - Class

class Station - Represents an individual railway station. Each station contains: String name;

3. Train - Class

class Train extends RailwayEntity - Represents a complete train and stores information such as:

  • Train number
  • Train name
  • Starting station
  • Departure time
  • Destination
  • Arrival time
  • Total distance
  • Off day
  • Passed stops
  • Next station
  • Next stop
  • Remaining journey information
  • List of stations

The class also provides: toFileString() to convert train information into the format used by train-data.txt

4. ITrainTracker - Interface

interface ITrainTracker - Defines the method: void updateUIContent();. The main application implements this interface so that the user interface can be dynamically updated whenever a train is selected


🖥️ USER INTERFACE | HOW IT WORKS?

🟢 0 | Program Startup

When the application starts, the main window displays:

train-tracker

The interface contains:

  • 🚉 Train selection dropdown
  • 🏛️ Government logo
  • 🚂 Bangladesh Railway logo
  • 📋 Train information panel
  • 📊 Train progress tracker
  • 📏 Remaining journey information
  • 👨🏻‍💻 Student/project information

✨ 1 | Select Train

The user can select one of the available trains from the dropdown:

Select Train

756-Madhumati Express
792-Banalata Express
754-Silkcity Express
760-Padma Express

Whenever the selection changes, the displayed information is automatically updated


📋 2 | Train Information Panel

For example, selecting Silkcity Express displays:

1. Train Number:        754
2. Train Name:          Silkcity Express
3. Start Station:       Rajshahi
4. Time of Departure:   07:40
5. Destination Station: Dhaka
6. Time of Arrival:     13:20
7. Number of Stops:     13
8. Next Station:        Ullapara
9. Next Stop:           Jamtail
10. Total Distance:     220 km

The exact values are loaded from the train data


🛤️ 3 | Progress Tracker

The bottom section displays the train's journey progress. Example:

●────●────●────●────●────●────●────●────●
🟢    🟢    🟢    🟢    🟢    🟢    🟢    🔴    🔴

The yellow portion represents the approximate travelled portion of the route. The application dynamically determines: Passed Stops and Total Stops, and paints the route accordingly


🚫 4 | Off-Day Message

The application compares the train's configured off day with the current system day. For example, if a train's off day is Sunday and the system day is Sunday:

TRAIN OFF DAY: SUNDAY

Not Operating Today

📏 5 | Remaining Journey

When the train is operating, the bottom of the information panel displays information such as Remaining 126 km in 02:50 hours


🚉 INCLUDED TRAIN INFORMATION

1. Madhumati Express - 756

Start:        Rajshahi
Departure:    06:40
Destination:  Dhaka
Arrival:      14:00
Distance:     220 km
Off Day:      Saturday
Passed Stops: 5
Next Station: Poradaha
Next Stop:    Kushtia Court

2. Banalata Express - 792

Start:        Chapainawabganj
Departure:    06:00
Destination:  Dhaka
Arrival:      11:35
Distance:     320 km
Off Day:      Friday
Passed Stops: 1
Next Station: Rajshahi
Next Stop:    Dhaka

3. Silkcity Express - 754

Start:        Rajshahi
Departure:    07:40
Destination:  Dhaka
Arrival:      13:20
Distance:     220 km
Off Day:      Sunday
Passed Stops: 7
Next Station: Ullapara
Next Stop:    Jamtail

4. Padma Express - 760

Start:        Rajshahi
Departure:    16:00
Destination:  Dhaka
Arrival:      21:15
Distance:     220 km
Off Day:      Tuesday
Passed Stops: 5
Next Station: Ullapara
Next Stop:    SHM Monsur Ali

📁 FILE STRUCTURE

/
├── main.java                 # Main Java application
├── assets/
|   ├── train-tracker.png     # Application interface
├── train-data.txt            # Persistent train information
├── govtLogo.png              # Government logo
├── railwayLogo.png           # Bangladesh Railway logo
└── README.md                 # Project documentation

📊 TRAIN DATA

The application stores train information using the following format:

ID  | Name              | Start Station    | Dep   | Dest     | Arr   | Dist   | Off Day  | # | Next St. | Next Sp.        | Progress Info                   | Stops
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
792 | Banalata Express  | Chapainawabganj  | 06:00 | Dhaka    | 11:35 | 320 km | Friday   | 1 | Rajshahi | Dhaka           | Remaining 280 km in 04:45 hours | 3 
754 | Silkcity Express  | Rajshahi         | 07:40 | Dhaka    | 13:20 | 220 km | Sunday   | 7 | Ullapara | Jamtail         | Remaining 126 km in 02:50 hours | 13
760 | Padma Express     | Rajshahi         | 16:00 | Dhaka    | 21:15 | 220 km | Tuesday  | 5 | Ullapara | SHM Monsur Ali  | Remaining 145 km in 03:20 hours | 12
756 | Madhumati Express | Rajshahi         | 06:40 | Dhaka    | 14:00 | 220 km | Saturday | 5 | Poradaha | Kushtia Court   | Remaining 170 km in 05:10 hours | 23

About

This Java program was developed as a part of my CSE 1203 (Object Oriented Programming) course. It demonstrates concepts of Java including classes, inheritance, abstraction, interfaces, file I/O, collections and Java Swing, simulating a train tracking application with train information, route progress and off-day detection

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages