Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Travel Booking System -- Project Documentation

Version: 1.0
Language: Java (Core Java Only)
Architecture: Single-file OOP
File: Main.java
Author: Project Team
Date: April 2026


Table of Contents

  1. Project Overview
  2. System Architecture
  3. Class Diagram (UML)
  4. Class Descriptions
  5. Sequence Diagrams
  6. Activity Diagrams
  7. OOP Principles Demonstrated
  8. Data Model
  9. Application Flow
  10. How to Run
  11. Trade-offs & Future Scope

1. Project Overview

The Travel Booking System is a fully interactive, colorful CLI application built entirely in Core Java inside a single file (Main.java). It simulates a real-world travel booking platform where users can:

  • Register and Login with credentials
  • Browse 5 predefined travel routes across India
  • Select travel modes (Bus or Flight) with real pricing
  • Choose from 5 rich day-wise itineraries (3 to 7 days) per route
  • Book seats and see a full price breakdown
  • Pay via UPI PIN validation
  • View all past bookings

Key Features

Feature Description
Authentication Register with name, email, password, phone, UPI PIN. Login via email + password
Routes 5 fixed routes: Delhi-Goa, Mumbai-Manali, Bangalore-Kerala, Chennai-Andaman, Hyderabad-Rajasthan
Travel Modes Bus (AC Sleeper, Non-AC, Semi-Sleeper) and Flight (Economy, Business) per route
Itineraries 5 day-wise itineraries per route (3-day through 7-day) with detailed plans
Booking Seat selection, price calculation, UPI payment, booking confirmation
CLI Design ANSI colored output with ASCII-safe formatting for Windows compatibility

2. System Architecture

The system follows a layered architecture even within a single file:

graph TD
    subgraph Presentation["Presentation Layer"]
        MAIN["Main (Entry Point + Static Banner)"]
        APP["TravelApp (CLI Controller)"]
        COLOR["Color (ANSI Utility)"]
    end

    subgraph Service["Service Layer"]
        AUTH["AuthService"]
        BOOK["BookingService"]
        PAY["UPIPayment"]
    end

    subgraph Data["Data Layer"]
        DS["DataStore (Static Routes + Modes)"]
        IG["ItineraryGenerator (Static Itinerary Data)"]
    end

    subgraph Model["Model Layer"]
        USER["User"]
        ROUTE["Route"]
        TM["TravelMode (Abstract)"]
        BUS["Bus"]
        FLT["Flight"]
        ITIN["Itinerary"]
        BKG["Booking"]
    end

    subgraph Contract["Interfaces"]
        PS["PaymentService"]
        DISP["Displayable"]
    end

    MAIN --> APP
    APP --> AUTH
    APP --> BOOK
    APP --> PAY
    APP --> DS
    APP --> IG
    PAY -.->|implements| PS
    ROUTE -.->|implements| DISP
    TM -.->|implements| DISP
    ITIN -.->|implements| DISP
    BKG -.->|implements| DISP
    BUS -->|extends| TM
    FLT -->|extends| TM

    style Presentation fill:#1a1a2e,color:#e94560
    style Service fill:#16213e,color:#0f3460
    style Data fill:#0f3460,color:#53354a
    style Model fill:#533483,color:#e94560
    style Contract fill:#2b2d42,color:#8d99ae
Loading

Layer Responsibilities

Layer Classes Responsibility
Presentation Main, TravelApp, Color Entry point, menu rendering, user interaction, ANSI formatting
Service AuthService, BookingService, UPIPayment Business logic: auth, booking, payment
Data DataStore, ItineraryGenerator Pre-loaded route/mode/itinerary data via static blocks
Model User, Route, TravelMode, Bus, Flight, Itinerary, Booking Domain entities with encapsulation
Interfaces PaymentService, Displayable Contracts for abstraction and polymorphism

3. Class Diagram (UML)

classDiagram
    class Main {
        +static main(String[] args)
    }

    class Color {
        +static String RESET
        +static String RED
        +static String GREEN
        +static String YELLOW
        +static String BLUE
        +static String PURPLE
        +static String CYAN
        +static String CYAN_BOLD
        +static String WHITE_BOLD
        +static String DIM
        +static void success(String msg)
        +static void error(String msg)
        +static void warn(String msg)
        +static void info(String msg)
        +static void header(String title)
        +static void menuItem(int num, String text)
        +static void divider()
        +static String prompt(String label)
        +static void price(String label, double amount)
    }

    class Displayable {
        <<interface>>
        +display() void
    }

    class PaymentService {
        <<interface>>
        +processPayment(User user, double amount, Scanner scanner) boolean
        +getPaymentMethod() String
    }

    class BookingException {
        +BookingException(String message)
    }

    class User {
        -String name
        -String email
        -String password
        -String phone
        -String upiPin
        +getName() String
        +getEmail() String
        +getPassword() String
        +getPhone() String
        +getUpiPin() String
        +validatePassword(String input) boolean
        +validateUpiPin(String input) boolean
    }

    class Route {
        -int id
        -String source
        -String destination
        -List~String~ attractions
        +getId() int
        +getSource() String
        +getDestination() String
        +getAttractions() List~String~
        +display() void
        +toString() String
    }

    class TravelMode {
        <<abstract>>
        -String name
        -double pricePerSeat
        -int seatsAvailable
        +getName() String
        +getPricePerSeat() double
        +getSeatsAvailable() int
        +hasSeats(int count) boolean
        +reserveSeats(int count) void
        +getModeType()* String
        +getModeTag()* String
        +display() void
    }

    class Bus {
        -String busType
        +getBusType() String
        +getModeType() String
        +getModeTag() String
    }

    class Flight {
        -String airlineClass
        +getAirlineClass() String
        +getModeType() String
        +getModeTag() String
    }

    class Itinerary {
        -int days
        -List~String~ dayPlans
        -List~String~ destinations
        -double price
        +getDays() int
        +getDayPlans() List~String~
        +getDestinations() List~String~
        +getPrice() double
        +display() void
        +toSummary() String
    }

    class Booking {
        -static int counter
        -String bookingId
        -String userEmail
        -Route route
        -TravelMode travelMode
        -Itinerary itinerary
        -int seatsBooked
        -double totalPrice
        -Date bookingDate
        +getUserEmail() String
        +getBookingId() String
        +getRoute() Route
        +getTravelMode() TravelMode
        +getItinerary() Itinerary
        +getSeatsBooked() int
        +getTotalPrice() double
        +display() void
    }

    class AuthService {
        -Map~String,User~ userStore
        +register(String, String, String, String, String) boolean
        +login(String email, String password) User
    }

    class UPIPayment {
        +processPayment(User, double, Scanner) boolean
        +getPaymentMethod() String
    }

    class BookingService {
        -List~Booking~ bookings
        +createBooking(String, Route, TravelMode, Itinerary, int) Booking
        +confirmBooking(Booking, TravelMode) void
        +getUserBookings(String userEmail) List~Booking~
    }

    class ItineraryGenerator {
        -static Map~Integer,List~ ROUTE_ATTRACTIONS
        -static Map~Integer,List~ ROUTE_DAY_ACTIVITIES
        +static generate(Route) List~Itinerary~
    }

    class DataStore {
        +static List~Route~ ROUTES
        +static Map~Integer,List~ TRAVEL_MODES
        +static getRouteById(int) Route
        +static getModesForRoute(int) List~TravelMode~
    }

    class TravelApp {
        -Scanner scanner
        -AuthService authService
        -BookingService bookingService
        -PaymentService paymentService
        -User currentUser
        +run() void
        -showAuthMenu() void
        -doRegister() void
        -doLogin() void
        -showMainMenu() void
        -viewRoutes() void
        -makeBooking() void
        -showMyBookings() void
    }

    BookingException --|> Exception
    TravelMode ..|> Displayable
    Route ..|> Displayable
    Itinerary ..|> Displayable
    Booking ..|> Displayable
    UPIPayment ..|> PaymentService
    Bus --|> TravelMode
    Flight --|> TravelMode

    Main --> TravelApp : creates
    TravelApp --> AuthService : uses
    TravelApp --> BookingService : uses
    TravelApp --> PaymentService : uses
    TravelApp --> DataStore : reads
    TravelApp --> ItineraryGenerator : generates
    TravelApp --> Color : formats output

    Booking *-- Route : contains
    Booking *-- TravelMode : contains
    Booking *-- Itinerary : contains
    AuthService o-- User : stores
    BookingService o-- Booking : stores
    DataStore o-- Route : stores
    DataStore o-- TravelMode : stores
Loading

4. Class Descriptions

4.1 Interfaces

Interface Methods Purpose
Displayable display() Common contract for all entities that can render themselves to CLI
PaymentService processPayment(), getPaymentMethod() Abstraction for payment processing; allows swapping UPI for Card, etc.

4.2 Abstract Class

Class Extends Purpose
TravelMode -- (implements Displayable) Base class for all travel options. Holds shared fields (name, price, seats) and seat management logic. Forces subclasses to define getModeType() and getModeTag()

4.3 Concrete Models

Class Key Fields Role
User name, email, password, phone, upiPin Immutable user profile with validation methods
Route id, source, destination, attractions Travel route with scenic attractions
Bus busType (AC Sleeper, Non-AC) Extends TravelMode for bus travel
Flight airlineClass (Economy, Business) Extends TravelMode for air travel
Itinerary days (3-7), dayPlans, destinations, price Day-wise travel plan with pricing
Booking bookingId, route, mode, itinerary, seats, totalPrice, date Complete booking record
BookingException message Custom checked exception for booking errors

4.4 Services

Class Implements Responsibility
AuthService -- User registration with validation, login with credential checking
BookingService -- Create bookings, validate seat availability, confirm + store bookings
UPIPayment PaymentService Validate UPI PIN against stored user PIN, simulate payment delay
ItineraryGenerator -- Generate 5 route-specific itineraries per route from static data
DataStore -- Static storage of 5 routes and their travel modes

4.5 Presentation

Class Role
Main Entry point with static block for ASCII banner
TravelApp Main application loop, menu rendering, full booking flow orchestration
Color ANSI escape code constants and formatted output helpers

5. Sequence Diagrams

5.1 User Registration Flow

sequenceDiagram
    participant U as User (CLI)
    participant TA as TravelApp
    participant AS as AuthService
    participant UM as User Model

    U->>TA: Select "Register" from Auth Menu
    TA->>U: Prompt for Name
    U->>TA: Enter "John Doe"
    TA->>U: Prompt for Email
    U->>TA: Enter "john@mail.com"
    TA->>U: Prompt for Password
    U->>TA: Enter "pass123"
    TA->>U: Prompt for Phone
    U->>TA: Enter "9876543210"
    TA->>U: Prompt for UPI PIN
    U->>TA: Enter "1234"

    TA->>AS: register(name, email, pass, phone, pin)
    AS->>AS: Validate email format
    AS->>AS: Check duplicate email
    AS->>AS: Validate password length >= 4
    AS->>AS: Validate UPI PIN is 4 digits
    AS->>AS: Validate phone length >= 10
    AS->>UM: new User(name, email, pass, phone, pin)
    UM-->>AS: User object created
    AS->>AS: userStore.put(email, user)
    AS-->>TA: return true
    TA->>U: Display "[OK] Registration successful!"
Loading

5.2 User Login Flow

sequenceDiagram
    participant U as User (CLI)
    participant TA as TravelApp
    participant AS as AuthService

    U->>TA: Select "Login" from Auth Menu
    TA->>U: Prompt for Email
    U->>TA: Enter "john@mail.com"
    TA->>U: Prompt for Password
    U->>TA: Enter "pass123"

    TA->>AS: login(email, password)
    AS->>AS: userStore.get(email)
    
    alt User not found
        AS-->>TA: return null
        TA->>U: Display "[X] No account found"
    else User found
        AS->>AS: user.validatePassword(password)
        alt Password incorrect
            AS-->>TA: return null
            TA->>U: Display "[X] Incorrect password"
        else Password correct
            AS-->>TA: return User object
            TA->>TA: currentUser = user
            TA->>U: Display "[OK] Welcome back, John Doe!"
        end
    end
Loading

5.3 Complete Booking Flow

sequenceDiagram
    participant U as User (CLI)
    participant TA as TravelApp
    participant DS as DataStore
    participant IG as ItineraryGenerator
    participant BS as BookingService
    participant PS as UPIPayment
    participant TM as TravelMode

    Note over U,TM: STEP 1: Route Selection
    TA->>DS: DataStore.ROUTES
    DS-->>TA: List of 5 Routes
    TA->>U: Display all routes
    U->>TA: Select Route ID (e.g., 3)
    TA->>DS: getRouteById(3)
    DS-->>TA: Route "Bangalore -> Kerala"

    Note over U,TM: STEP 2: Travel Mode Selection
    TA->>DS: getModesForRoute(3)
    DS-->>TA: List of TravelModes (Flights + Buses)
    TA->>U: Display all modes with prices & seats
    U->>TA: Select mode (e.g., 1 = IndiGo Economy)

    Note over U,TM: STEP 3: Itinerary Selection
    TA->>IG: ItineraryGenerator.generate(route)
    IG-->>TA: 5 Itineraries (3-day to 7-day)
    TA->>U: Display all 5 itineraries with day-wise plans
    U->>TA: Select itinerary (e.g., 3 = 5-Day)

    Note over U,TM: STEP 4: Seat Selection & Payment
    U->>TA: Enter number of seats (e.g., 2)
    TA->>BS: createBooking(email, route, mode, itinerary, 2)
    BS->>BS: Validate seats > 0
    BS->>TM: mode.hasSeats(2)
    TM-->>BS: true
    BS->>BS: totalPrice = 2 * (3200 + 5000) = Rs.16400
    BS-->>TA: Booking object (not yet confirmed)

    TA->>U: Display price breakdown
    TA->>PS: processPayment(user, 16400, scanner)
    PS->>U: Prompt for UPI PIN
    U->>PS: Enter "1234"
    PS->>PS: user.validateUpiPin("1234")
    PS->>PS: Simulate processing delay
    PS-->>TA: return true (payment success)

    TA->>BS: confirmBooking(booking, mode)
    BS->>TM: mode.reserveSeats(2)
    TM->>TM: seatsAvailable -= 2
    BS->>BS: bookings.add(booking)
    BS-->>TA: Booking confirmed

    TA->>U: Display Booking confirmation card
Loading

5.4 View Bookings Flow

sequenceDiagram
    participant U as User (CLI)
    participant TA as TravelApp
    participant BS as BookingService

    U->>TA: Select "Show My Bookings"
    TA->>BS: getUserBookings(currentUser.email)
    BS->>BS: Filter bookings by email
    BS-->>TA: List of user's bookings

    alt No bookings
        TA->>U: Display "[!] No bookings yet"
    else Has bookings
        TA->>U: Display total count
        loop For each booking
            TA->>U: Display booking card with ID, route, mode, itinerary, seats, price, date
        end
    end
Loading

6. Activity Diagrams

6.1 Application Main Flow

flowchart TD
    START([Application Start]) --> BANNER[Display ASCII Banner via Static Block]
    BANNER --> CHECK{User Logged In?}

    CHECK -->|No| AUTH_MENU[Show Auth Menu]
    AUTH_MENU --> AUTH_CHOICE{Choice?}

    AUTH_CHOICE -->|1 - Login| LOGIN[Prompt Email + Password]
    LOGIN --> VALIDATE_LOGIN{Credentials Valid?}
    VALIDATE_LOGIN -->|Yes| SET_USER[Set currentUser]
    SET_USER --> CHECK
    VALIDATE_LOGIN -->|No| ERR1[Show Error Message]
    ERR1 --> CHECK

    AUTH_CHOICE -->|2 - Register| REGISTER[Prompt Name, Email, Pass, Phone, PIN]
    REGISTER --> VALIDATE_REG{All Validations Pass?}
    VALIDATE_REG -->|Yes| STORE_USER[Store User in HashMap]
    STORE_USER --> SUC1[Show Success Message]
    SUC1 --> CHECK
    VALIDATE_REG -->|No| ERR2[Show Validation Error]
    ERR2 --> CHECK

    AUTH_CHOICE -->|3 - Exit| EXIT_APP([Exit Application])

    CHECK -->|Yes| MAIN_MENU[Show Main Menu]
    MAIN_MENU --> MAIN_CHOICE{Choice?}

    MAIN_CHOICE -->|1| VIEW_ROUTES[Display All 5 Routes]
    VIEW_ROUTES --> CHECK

    MAIN_CHOICE -->|2| BOOKING_FLOW[Start Booking Flow]
    BOOKING_FLOW --> CHECK

    MAIN_CHOICE -->|3| VIEW_BOOKINGS[Display User's Bookings]
    VIEW_BOOKINGS --> CHECK

    MAIN_CHOICE -->|4| LOGOUT[Set currentUser = null]
    LOGOUT --> CHECK

    style START fill:#2ecc71,color:#fff
    style EXIT_APP fill:#e74c3c,color:#fff
    style BANNER fill:#9b59b6,color:#fff
    style AUTH_MENU fill:#3498db,color:#fff
    style MAIN_MENU fill:#3498db,color:#fff
Loading

6.2 Booking Flow Activity Diagram

flowchart TD
    START([Make Booking Selected]) --> SHOW_ROUTES[Display All Routes]
    SHOW_ROUTES --> INPUT_ROUTE[/User Enters Route ID/]
    INPUT_ROUTE --> VALID_ROUTE{Valid Route ID?}

    VALID_ROUTE -->|No| ERR_ROUTE[Show Error, Return to Menu]
    ERR_ROUTE --> END_FAIL([Return to Main Menu])

    VALID_ROUTE -->|Yes| SHOW_MODES[Display Travel Modes for Route]
    SHOW_MODES --> INPUT_MODE[/User Selects Travel Mode/]
    INPUT_MODE --> VALID_MODE{Valid Mode?}

    VALID_MODE -->|No| ERR_MODE[Show Error, Return to Menu]
    ERR_MODE --> END_FAIL

    VALID_MODE -->|Yes| GEN_ITIN[Generate 5 Itineraries for Route]
    GEN_ITIN --> SHOW_ITIN[Display All Itineraries with Day Plans]
    SHOW_ITIN --> INPUT_ITIN[/User Selects Itinerary/]
    INPUT_ITIN --> VALID_ITIN{Valid Itinerary?}

    VALID_ITIN -->|No| ERR_ITIN[Show Error, Return to Menu]
    ERR_ITIN --> END_FAIL

    VALID_ITIN -->|Yes| INPUT_SEATS[/User Enters Number of Seats/]
    INPUT_SEATS --> VALID_SEATS{Seats > 0 AND Available?}

    VALID_SEATS -->|No| ERR_SEATS[Show Error via BookingException]
    ERR_SEATS --> END_FAIL

    VALID_SEATS -->|Yes| CALC_PRICE[Calculate Total Price]
    CALC_PRICE --> SHOW_BREAKDOWN[Display Price Breakdown]
    SHOW_BREAKDOWN --> UPI_PIN[/User Enters UPI PIN/]
    UPI_PIN --> VALIDATE_PIN{PIN Correct?}

    VALIDATE_PIN -->|No| PAY_FAIL[Payment Failed Message]
    PAY_FAIL --> END_FAIL

    VALIDATE_PIN -->|Yes| PAY_SUCCESS[Payment Success]
    PAY_SUCCESS --> RESERVE[Reserve Seats on TravelMode]
    RESERVE --> STORE_BOOKING[Store Booking in BookingService]
    STORE_BOOKING --> CONFIRM[Display Booking Confirmation Card]
    CONFIRM --> END_OK([Return to Main Menu])

    style START fill:#2ecc71,color:#fff
    style END_OK fill:#2ecc71,color:#fff
    style END_FAIL fill:#e74c3c,color:#fff
    style CALC_PRICE fill:#f39c12,color:#fff
    style PAY_SUCCESS fill:#27ae60,color:#fff
    style PAY_FAIL fill:#c0392b,color:#fff
Loading

6.3 Payment Processing Activity Diagram

flowchart TD
    START([Payment Initiated]) --> SHOW_AMOUNT[Display Amount Due]
    SHOW_AMOUNT --> PROMPT_PIN[/Prompt for UPI PIN/]
    PROMPT_PIN --> CHECK_EMPTY{PIN Empty?}

    CHECK_EMPTY -->|Yes| THROW[Throw BookingException]
    THROW --> FAIL([Payment Failed])

    CHECK_EMPTY -->|No| SIMULATE[Simulate Processing Delay -- 1.5s]
    SIMULATE --> VALIDATE{PIN matches stored PIN?}

    VALIDATE -->|Yes| SUCCESS[Display Payment Success]
    SUCCESS --> RETURN_TRUE([Return true])

    VALIDATE -->|No| INCORRECT[Display Incorrect PIN Error]
    INCORRECT --> RETURN_FALSE([Return false])

    style START fill:#3498db,color:#fff
    style RETURN_TRUE fill:#2ecc71,color:#fff
    style RETURN_FALSE fill:#e74c3c,color:#fff
    style FAIL fill:#e74c3c,color:#fff
    style SIMULATE fill:#f39c12,color:#fff
Loading

6.4 Registration Validation Activity Diagram

flowchart TD
    START([Registration Request]) --> V1{Email blank?}
    V1 -->|Yes| E1[Error: Email cannot be empty]
    E1 --> FAIL([Return false])

    V1 -->|No| V2{Email contains @ and .?}
    V2 -->|No| E2[Error: Invalid email format]
    E2 --> FAIL

    V2 -->|Yes| V3{Email already registered?}
    V3 -->|Yes| E3[Error: Account exists]
    E3 --> FAIL

    V3 -->|No| V4{Password length >= 4?}
    V4 -->|No| E4[Error: Password too short]
    E4 --> FAIL

    V4 -->|Yes| V5{UPI PIN is 4 digits?}
    V5 -->|No| E5[Error: Invalid UPI PIN]
    E5 --> FAIL

    V5 -->|Yes| V6{Phone length >= 10?}
    V6 -->|No| E6[Error: Invalid phone]
    E6 --> FAIL

    V6 -->|Yes| CREATE[Create User Object]
    CREATE --> STORE[Store in HashMap]
    STORE --> SUCCESS([Return true])

    style START fill:#3498db,color:#fff
    style SUCCESS fill:#2ecc71,color:#fff
    style FAIL fill:#e74c3c,color:#fff
Loading

7. OOP Principles Demonstrated

7.1 Encapsulation

All model classes use private final fields with public getters only. No direct field access is allowed from outside the class.

User:
  - private final String name       --> getName()
  - private final String email      --> getEmail()
  - private final String upiPin     --> validateUpiPin() (no direct getter exposure for PIN)

TravelMode:
  - private int seatsAvailable      --> managed internally via reserveSeats() and hasSeats()

Key design: User.validateUpiPin() hides the comparison logic internally -- callers never see the raw PIN value.

7.2 Abstraction

Mechanism Example
Interface PaymentService defines what payment does (processPayment, getPaymentMethod) without how
Interface Displayable defines that entities can render themselves, hiding implementation
Abstract Class TravelMode provides shared seat management but forces subclasses to define mode-specific labels

7.3 Inheritance

TravelMode (abstract)
    |
    +-- Bus      (adds: busType field, overrides getModeType/getModeTag)
    +-- Flight   (adds: airlineClass field, overrides getModeType/getModeTag)

Bus and Flight inherit:

  • name, pricePerSeat, seatsAvailable fields
  • hasSeats(), reserveSeats() methods
  • display() rendering logic

But provide their own:

  • getModeType() -- returns "Bus (AC Sleeper)" vs "Flight (Economy)"
  • getModeTag() -- returns "[BUS]" vs "[FLY]"

7.4 Polymorphism

Type Where Used
Runtime (Method Overriding) Bus.getModeType() and Flight.getModeType() called via TravelMode reference in booking flow
Runtime (Interface) UPIPayment.processPayment() called via PaymentService reference in TravelApp
Runtime (Displayable) Route.display(), Itinerary.display(), Booking.display() all called through Displayable contract

Example in code:

// TravelApp holds PaymentService reference (interface)
private final PaymentService paymentService = new UPIPayment();
// Can be swapped to: new CardPayment() without changing TravelApp

7.5 Collections Framework Usage

Collection Class Purpose
HashMap<String, User> AuthService User storage keyed by email for O(1) lookup
ArrayList<Booking> BookingService Ordered list of all bookings
ArrayList<Route> DataStore List of predefined routes
HashMap<Integer, List<TravelMode>> DataStore Route ID -> available travel modes mapping
HashMap<Integer, List<List<String>>> ItineraryGenerator Route ID -> attraction/activity data

7.6 Static Blocks

Class Static Block Purpose
Main Display ASCII art banner on class loading
DataStore Initialize 5 routes and their travel modes
ItineraryGenerator Load route-specific attraction and activity data for all 5 routes

7.7 Exception Handling

Exception Where
BookingException (custom checked) Seat unavailable, empty UPI PIN, invalid seat count
InputMismatchException Non-numeric input where int expected
IllegalArgumentException Itinerary days outside 3-7 range
Exception (catch-all) Safety net in main loop

8. Data Model

8.1 Routes

ID Source Destination Key Attractions
1 Delhi Goa Baga Beach, Fort Aguada, Dudhsagar Falls
2 Mumbai Manali Solang Valley, Rohtang Pass, Hadimba Temple
3 Bangalore Kerala Alleppey Backwaters, Munnar, Fort Kochi
4 Chennai Andaman Radhanagar Beach, Cellular Jail, Ross Island
5 Hyderabad Rajasthan Amber Fort, Sam Sand Dunes, Lake Pichola

8.2 Travel Modes per Route

Route Mode Operator Price/Seat Seats
Delhi-Goa Flight (Economy) Air India Express Rs.4500 120
Delhi-Goa Flight (Business) IndiGo Airlines Rs.5200 80
Delhi-Goa Bus (AC Sleeper) RedBus Volvo Rs.1800 40
Delhi-Goa Bus (Non-AC) RSRTC Deluxe Rs.1200 50
Mumbai-Manali Flight (Economy) SpiceJet Rs.5800 100
Mumbai-Manali Flight (Business) Vistara Rs.8500 60
Mumbai-Manali Bus (AC Sleeper) HRTC Volvo Rs.2200 36
Mumbai-Manali Bus (Semi-Sleeper) Private Travels Rs.1500 44
Bangalore-Kerala Flight (Economy) IndiGo Rs.3200 150
Bangalore-Kerala Bus (AC Sleeper) KSRTC Airavat Rs.1400 48
Chennai-Andaman Flight (Economy) GoAir Rs.5500 90
Chennai-Andaman Flight (Business) Air India Rs.9200 40
Hyderabad-Rajasthan Flight (Economy) IndiGo Rs.4800 110
Hyderabad-Rajasthan Bus (AC Sleeper) SRS Travels Rs.2000 38

Note

Chennai-Andaman has no bus options since Andaman is an island -- only flights are available.

8.3 Itinerary Pricing

Duration Price
3-Day Rs.2500
4-Day Rs.3500
5-Day Rs.5000
6-Day Rs.6500
7-Day Rs.8500

8.4 Total Price Formula

TOTAL PRICE = number_of_seats * (travel_price_per_seat + itinerary_price)

Example: 2 seats on IndiGo Economy (Rs.3200) + 5-Day Kerala itinerary (Rs.5000)

= 2 * (3200 + 5000) = Rs.16,400.00

9. Application Flow

9.1 State Diagram

stateDiagram-v2
    [*] --> NotLoggedIn : App starts, banner displays

    state NotLoggedIn {
        [*] --> AuthMenu
        AuthMenu --> Login : Option 1
        AuthMenu --> Register : Option 2
        AuthMenu --> [*] : Option 3 (Exit)
        Login --> AuthMenu : Failed
        Register --> AuthMenu : Complete
    }

    NotLoggedIn --> LoggedIn : Login Success

    state LoggedIn {
        [*] --> MainMenu
        MainMenu --> ViewRoutes : Option 1
        MainMenu --> MakeBooking : Option 2
        MainMenu --> ShowBookings : Option 3
        ViewRoutes --> MainMenu
        ShowBookings --> MainMenu

        state MakeBooking {
            [*] --> SelectRoute
            SelectRoute --> SelectMode : Valid route
            SelectMode --> SelectItinerary : Valid mode
            SelectItinerary --> SelectSeats : Valid itinerary
            SelectSeats --> Payment : Valid seats
            Payment --> BookingConfirmed : PIN correct
            Payment --> BookingFailed : PIN wrong
        }
        MakeBooking --> MainMenu
    }

    LoggedIn --> NotLoggedIn : Logout (Option 4)
Loading

9.2 Error Handling Flow

All exceptions in the main loop are caught gracefully:

TravelApp.run()
  |
  +-- try { showAuthMenu() / showMainMenu() }
  |
  +-- catch BookingException     --> Color.error(message)
  +-- catch InputMismatchException --> Color.error("Invalid input") + scanner.nextLine()
  +-- catch Exception            --> Color.error("Something went wrong: " + message)
  |
  +-- Loop continues (app never crashes)

10. How to Run

Prerequisites

  • Java JDK 11 or higher installed
  • Terminal that supports ANSI escape codes (Windows Terminal, PowerShell, VS Code Terminal)

Steps

# 1. Navigate to project directory
cd c:\Users\mdmeh\khamma\Travel_Booking_System

# 2. Compile
javac Main.java

# 3. Run
java Main

Expected Output on Launch

  ######################################################
  #                                                    #
  #        T R A V E L   B O O K I N G               #
  #              S Y S T E M                          #
  #                                                    #
  ######################################################
        Powered by Core Java | OOP Architecture

  ######################################################
  #           WELCOME -- TRAVEL BOOKING SYSTEM
  ######################################################
    [1] Login
    [2] Register
    [3] Exit

  >> Choose option:

11. Trade-offs & Future Scope

11.1 Single-File Trade-offs

Aspect Current (Single File) Multi-File (Future)
Compilation javac Main.java -- one command Build tool (Maven/Gradle) needed
Readability Sectioned with comments, ~1000 lines Each class in own file
Testability Cannot unit-test classes independently JUnit per class
IDE Navigation Basic search Full package navigation
Deployment Copy one file JAR with manifest

Important

Despite the single-file constraint, every class is fully self-contained. To migrate to multi-file, simply move each class to its own .java file and add package declarations -- zero logic changes needed.

11.2 Extension Points

Extension How
New payment method Implement PaymentService interface (e.g., CardPayment)
New travel mode Extend TravelMode abstract class (e.g., Train, Cab)
New routes Add entries to DataStore static block
Persistence Replace HashMap/ArrayList with file I/O or database
Search/Filter Add methods to DataStore for price range, destination filters
Cancellation Add cancelBooking() to BookingService + refund in TravelMode.releaseSeats()

About

all the essential docs

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors