SkyRoute is a comprehensive console-based ticket booking application built in Java. It allows users to register, log in, search for routes, book tickets for planes, trains, and buses, view their bookings, and cancel them. The system also features an admin dashboard for managing bookings and users at a higher level. It emphasizes data-driven route selection, provider choice, input validation, and persistent storage of user and booking information.
- User Management:
- Secure user registration with password hashing (SHA-256).
- User login with password verification.
- Data persistence for user accounts in
users.txt.
- Admin Functionality:
- Dedicated admin login (default:
admin/admin). - Admin dashboard with options to:
- View all bookings across all users and services.
- View a list of all registered users.
- Cancel any booking in the system using its Booking ID.
- Dedicated admin login (default:
- Booking Process:
- Transport Selection: Choose between Plane, Train, or Bus.
- Route Selection: Select origin and destination cities from lists dynamically populated from data files (
airports.txt,train_stations.txt,bus_stations.txt). - Route Details Display: Shows distance and estimated travel time for the selected route.
- Provider Selection: Users choose a specific service provider (e.g., "IndiGo 6E-201", "Rajdhani Express") for their chosen route.
- Travel Date Input: Validated date input (DD-MM-YYYY, future dates only).
- Class Selection: Different travel classes available for planes and trains with corresponding price multipliers. Buses use a "Standard" class.
- Seat Selection: Interactive seat map display (
Ofor available,Xfor reserved). Users select seats by row and column. - Passenger Details: Collects passenger name, age, gender, and email with input validation.
- Payment Simulation: A simulated payment process (no actual payment is processed).
- Booking Confirmation: Displays a detailed confirmation upon successful booking.
- Booking Management:
- View all bookings made by the logged-in user.
- Cancel existing bookings.
- Data Persistence:
- User accounts are saved in
users.txt. - Confirmed bookings are saved in
bookings.txt.
- User accounts are saved in
- User Interface:
- Console-based interface with styled menus, prompts, and messages using ANSI color codes for better readability.
- Password masking during input (works best when run directly in a system terminal).
The project is organized into several Java classes within the TicketBookingSystem package, supported by text-based data files.
Main.java:- Purpose: Application entry point, main menu, overall flow control.
- Responsibilities: Initializes core components, handles default admin creation, displays the primary menu (Register, Login, View Routes, Exit), directs users to appropriate dashboards (Admin or User), and manages application exit (including data saving).
UserManager.java:- Purpose: Handles user authentication and account management.
- Responsibilities: User registration (with password hashing), user login (verifying credentials), password hashing (SHA-256), providing user data to
StorageManagerandAdminDashboard.
BookingSystem.java:- Purpose: Orchestrates the booking process for regular (non-admin) users.
- Responsibilities: Manages lists of vehicle booking "manager" objects (
PlaneBooking,TrainBooking,BusBooking), interacts withRouteDataManagerfor route and provider selection, handles class and date selection, calls the appropriate vehicle manager to finalize booking, manages user's own booking viewing and cancellation.
AdminDashboard.java:- Purpose: Provides a dedicated interface for administrative tasks.
- Responsibilities: Displays admin-specific menu, allows viewing of all bookings across all users, lists all registered users (via
UserManager), enables cancellation of any booking by ID.
RouteDataManager.java:- Purpose: Loads, parses, and provides access to route information from data files.
- Responsibilities: Reads and parses
airports.txt,train_stations.txt,bus_stations.txt. Stores route details (distance, ETA, providers) and location information. Provides this data toBookingSystemfor user choices and toMainfor the "View Route Information" feature.
PlaneBooking.java/TrainBooking.java/BusBooking.java:- Purpose: Each class acts as a "manager" for bookings related to its transport type. It handles the specifics of seat layout, booking finalization, and stores bookings associated with its generic manager ID (e.g., "PLANE-MANAGER-1").
- Responsibilities: Initializes and displays seat layouts (using
CustomLinkedList<Seat>), handles seat selection by the user, collects validated passenger details, simulates payment, creates and storesBookingrecords (including the specific service provider chosen by the user), displays bookings for a user relevant to this manager, and handles booking cancellations for bookings it manages.
StorageManager.java:- Purpose: Handles persistence of user and booking data to text files.
- Responsibilities: Saves and loads user credentials (username and hashed passwords) to/from
users.txt. Saves and loads confirmed booking details (including provider information) to/frombookings.txt.
Seat.java:- Purpose: Data model representing a single seat.
- Responsibilities: Stores seat properties (row, column, class, type, price, reserved status). Provides methods to reserve/unreserve and display its status.
Passenger.java:- Purpose: Data model representing a passenger.
- Responsibilities: Stores passenger details (name, age, gender, email) and the
Seatobject they booked.
CustomLinkedList.java:- Purpose: A generic, singly linked list implementation.
- Responsibilities: Used by
Plane/Train/BusBookingclasses to temporarily manage and display the list ofSeatobjects for a specific booking transaction. ImplementsIterable.
Utils.java:- Purpose: Provides static utility methods used across the application.
- Responsibilities: Defines ANSI color constants for console styling, methods for
pause,clearScreen,printBanner, base price calculation, input validation (getValidTravelDate,getValidAge,getValidGender,getValidEmail), and payment simulation.
users.txt: Storesusername:hashedPassword.bookings.txt: Stores confirmed bookings. Format:BookingID:Username:StartCity:DestCity:Price:SeatClass:SeatRow:SeatCol:VehicleManagerID:TravelDate:Providerairports.txt,train_stations.txt,bus_stations.txt: Define locations, routes, distances, ETAs, and service providers. Format:City|PrimaryName[|AltName1|AltName2...]|RouteDetailsStringwhereRouteDetailsStringisDest1:Dist1:ETA1:ProvA,ProvB;Dest2....
The project utilizes various standard Java libraries. Some key imports include:
java.util.Scanner: For reading user input from the console.java.util.List,java.util.ArrayList: For managing dynamic collections of objects (e.g., vehicle managers, providers, sorted lists for display).java.util.Map,java.util.HashMap: For storing key-value pairs (e.g., user credentials, bookings, route data).java.util.Collections: For sorting lists (e.g., displaying cities or users alphabetically).java.io.*(e.g.,BufferedReader,BufferedWriter,FileReader,FileWriter,File,Console): For file input/output operations and console interactions (password masking).java.security.MessageDigest,java.security.NoSuchAlgorithmException: For password hashing using SHA-256.java.time.*(e.g.,LocalDate,DateTimeFormatter,DateTimeParseException,ResolverStyle): For robust date handling and validation.java.util.regex.Pattern: For basic email validation.java.util.InputMismatchException: For handling errors when reading numeric input.
- Arrays:
- Used in
Plane/Train/BusBooking(e.g.,char[] columns) for defining basic seat column layouts. - Used in
Utils(e.g.,VALID_GENDERSinitialized fromArrays.asList). - String splitting (
split()) results in arrays, used extensively in parsing data from files (RouteDataManager,StorageManager).
- Used in
- Linked Lists:
CustomLinkedList<T>: A custom generic singly linked list is implemented to manageSeatobjects during a booking transaction. This demonstrates understanding of node-based data structures, traversal, addition, and removal operations.- Conceptual Use: Used for dynamic storage where the number of elements (seats in a layout) is determined at runtime based on class, and elements need to be iterated over.
- Hash Maps (Hash Tables):
HashMap<String, String> usersinUserManager: Stores username-password (hash) pairs. Provides O(1) average time complexity for lookups (checking if a user exists, retrieving a stored password hash), registrations (checking for existing username), and logins.Map<String, Booking> bookingsinPlane/Train/BusBooking: Stores booking ID toBookingobject mappings. Allows efficient retrieval and cancellation of bookings by ID.Map<String, LocationInfo> airport/busStation/trainStationDatainRouteDataManager: Stores city names (keys) to detailedLocationInfoobjects. Provides efficient lookup of location details and their available routes.Map<String, RouteDetail> routeswithinLocationInfo: Stores destination city names toRouteDetailobjects, allowing efficient lookup of specific route information from a given origin.
- Sets:
Set<String> VALID_GENDERSinUtils: Uses aHashSetfor efficient checking (contains()) if a provided gender string (after converting to uppercase) is one of the allowed options. O(1) average time complexity for lookups.
- Lists (Dynamic Arrays):
ArrayList<Plane/Train/BusBooking>inBookingSystem: Manages the collection of vehicle booking manager objects.ArrayList<String> providersinRouteDetail: Stores the list of service providers for a route.ArrayList<String>used for sorting keys inRouteDataManagerandUserManagerbefore displaying lists to the user for better readability (e.g.,originCityKeys,destinationKeys,sortedUsernames).
- Strings and String Manipulation:
- Extensively used for parsing data from files (splitting lines by delimiters), formatting output for display, and handling user input.
- Searching:
- Linear Search:
- Implicit in
CustomLinkedList.remove()andCustomLinkedList.contains(). findSeat()inPlane/Train/BusBookingperforms a linear search through theCustomLinkedList<Seat>.- Locating the correct
Plane/Train/BusBookingmanager object inBookingSystemduring loading or cancellation involves iterating through theArrayListof these objects (linear search).
- Implicit in
- Hash-based Search: Utilized by
HashMap.containsKey()andHashMap.get()for O(1) average time lookups inUserManager,RouteDataManager, and thebookingsmaps within vehicle booking classes.
- Linear Search:
- Sorting:
Collections.sort(): Used to sort lists of city names, destination names, and usernames alphabetically before displaying them to the user, enhancing user experience. This typically uses a variation of MergeSort or TimSort in Java, offering O(n log n) time complexity.
- Recursion:
- A light form of recursion is used in
BookingSystem.selectValidRoute()if the user chooses to go "Back to Origin Selection" from the destination selection menu, the method calls itself to restart the origin selection.
- A light form of recursion is used in
- Hashing (Cryptographic):
- SHA-256: Used in
UserManager.hashPassword()for secure one-way hashing of passwords before storage. This is a cryptographic concept, not a typical DSA data structure, but an important algorithm used.
- SHA-256: Used in
Prerequisites:
- Java Development Kit (JDK) installed (version 17 or newer recommended for records, but adaptable).
- A terminal or command prompt that supports ANSI escape codes for styled output (e.g., Windows Terminal, PowerShell, macOS Terminal, most Linux terminals).
Compilation:
- Ensure all
.javafiles are in a directory structure matching their package statement (e.g.,TicketBookingSystemfolder). - Navigate to the directory containing the
TicketBookingSystempackage folder in your terminal. - Compile all Java files:
Or, to compile into a separate
javac TicketBookingSystem/*.javaoutdirectory (recommended):(Assuming your source files are injavac -d out src/TicketBookingSystem/*.javasrc/TicketBookingSystemand you are in the project root).
Running:
- Ensure the data files (
airports.txt,train_stations.txt,bus_stations.txt) are present in the execution directory (usually the project root if running from there, or the directory whereTicketBookingSystem.Main.classis located). users.txtandbookings.txtwill be created automatically in the execution directory if they don't exist.- From the directory where the compiled
TicketBookingSystempackage is accessible (e.g., from the project root if you used-d outabove, thencd out):java TicketBookingSystem.Main
First Run & Admin Login:
- On the very first run (or if
users.txtis deleted/empty), the application will create a default admin user:- Username:
admin - Password:
admin
- Username:
- To log in as admin, select the "Login" option and use these credentials.
Password Masking Note:
Password input masking (not showing characters as they are typed) is handled by java.io.Console.readPassword(). This works best when running the application from a true system terminal. Many IDE-integrated consoles do not fully support this, and passwords might be visible during input in such environments (the system will fall back to standard input).
The application uses ANSI escape codes, managed via constants in the Utils class, to provide:
- Colored text for menus, prompts, success messages, warnings, and errors.
- Bolding for emphasis.
- Styled banners for section titles.
- Colored indicators for seat availability (
OvsX).
This enhances the command-line user interface's readability and visual appeal.