You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
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
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)privatefinalPaymentServicepaymentService = newUPIPayment();
// 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
Terminal that supports ANSI escape codes (Windows Terminal, PowerShell, VS Code Terminal)
Steps
# 1. Navigate to project directorycd 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.