Skip to content

Vikash565-dot/Advance-train

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

Repository files navigation

Advanced Rail Ticket Booking System

A comprehensive console-based rail ticket booking system built with Core Java 8 featuring advanced OOP concepts, functional programming, and robust error handling.

πŸš‚ Features

User Management

  • βœ… User registration with validation
  • βœ… Secure user login/logout
  • βœ… Profile management
  • βœ… Booking history tracking

Train Management

  • βœ… Comprehensive train database with 15+ sample trains
  • βœ… Search trains by:
    • Route (source β†’ destination)
    • Train number
    • Source station
    • Destination station
    • Train name
  • βœ… Sort trains by departure time and fare
  • βœ… Real-time seat availability

Booking System

  • βœ… Interactive ticket booking with passenger details
  • βœ… Dynamic fare calculation with discounts:
    • 50% for children (age < 12)
    • 10% for senior citizens (age β‰₯ 60)
  • βœ… Automatic seat assignment
  • βœ… PNR generation and management
  • βœ… Booking confirmation with detailed ticket

Cancellation & Refund

  • βœ… Ticket cancellation with PNR
  • βœ… Smart refund calculation:
    • 90% refund (β‰₯24 hours before journey)
    • 75% refund (β‰₯12 hours before journey)
    • 50% refund (β‰₯2 hours before journey)
    • No refund (<2 hours before journey)

Advanced Features

  • βœ… PNR status checking
  • βœ… Comprehensive booking history
  • βœ… Input validation and error handling
  • βœ… Thread-safe booking operations
  • βœ… Functional programming with Java 8

πŸ›  Technical Stack

  • Language: Core Java 8
  • Features Used:
    • Streams & Filters
    • Lambda Expressions
    • Functional Interfaces
    • Optional for null-safe operations
    • LocalDate/LocalDateTime for date handling
  • Data Storage: In-memory collections (HashMap, ArrayList)
  • Design Patterns: Service layer architecture
  • Thread Safety: Synchronized booking operations

πŸ“ Project Structure

src/
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ User.java              # User entity
β”‚   β”œβ”€β”€ Train.java             # Train entity
β”‚   β”œβ”€β”€ Passenger.java         # Passenger entity
β”‚   β”œβ”€β”€ Ticket.java            # Ticket entity
β”‚   └── PNR.java               # PNR utility
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ AuthenticationService.java    # User auth & management
β”‚   β”œβ”€β”€ TrainDatabase.java           # Train data operations
β”‚   └── BookingSystem.java           # Booking & cancellation logic
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ DisplayUtils.java            # UI formatting utilities
β”‚   └── ValidationUtils.java         # Input validation utilities
β”œβ”€β”€ exceptions/
β”‚   └── BookingException.java        # Custom exception handling
└── MainApp.java                     # Main application entry point

πŸš€ How to Run

Prerequisites

  • Java 8+ installed
  • Any Java IDE (VS Code, IntelliJ, Eclipse) or command line

Running the Application

  1. Using Command Line:

    # Navigate to project directory
    cd "c:\Users\harsh\Desktop\Train"
    
    # Compile all Java files
    javac -d bin src/**/*.java src/*.java
    
    # Run the application
    java -cp bin MainApp
  2. Using VS Code:

    • Open the project folder in VS Code
    • Use Ctrl+F5 to run without debugging
    • Or use the Run button in the editor
  3. Using IDE:

    • Import the project
    • Run the MainApp.java file

πŸ“‹ Usage Guide

1. Registration & Login

  • Register with username, password, email, and phone
  • Login with credentials to access the booking system

2. Search Trains

  • Search by route, train number, or station
  • View detailed train information
  • Check real-time seat availability

3. Book Tickets

  • Select train and journey date
  • Enter passenger details (up to 6 passengers)
  • Get automatic fare calculation with discounts
  • Receive PNR and seat assignments

4. Manage Bookings

  • Check PNR status anytime
  • View complete booking history
  • Cancel tickets with refund calculation

πŸ§ͺ Sample Data

The system comes pre-loaded with 15 sample trains covering major Indian routes:

  • Rajdhani Express (Delhi-Mumbai, Delhi-Howrah, Delhi-Bangalore)
  • Shatabdi Express (Delhi-Bhopal, Delhi-Kalka, Mumbai-Ahmedabad)
  • Various other express trains connecting major cities

🎯 Key Java 8 Features Demonstrated

Streams & Lambda Expressions

// Filter trains by route
List<Train> trains = trainMap.values().stream()
    .filter(train -> train.getSource().equalsIgnoreCase(source))
    .filter(train -> train.getDestination().equalsIgnoreCase(destination))
    .collect(Collectors.toList());

// Sort trains by departure time
List<Train> sortedTrains = trains.stream()
    .sorted(Comparator.comparing(Train::getDepartureTime))
    .collect(Collectors.toList());

Functional Interfaces

@FunctionalInterface
public interface RefundCalculator {
    double calculateRefund(Ticket ticket, long hoursBeforeJourney);
}

// Usage with lambda
RefundCalculator refundCalculator = (ticket, hours) -> {
    if (hours >= 24) return ticket.getTotalFare() * 0.9;
    else if (hours >= 12) return ticket.getTotalFare() * 0.75;
    // ... more conditions
};

Optional Usage

// Null-safe operations
Optional<Train> trainOpt = trainDatabase.findTrainByNumber(trainNumber);
trainOpt.ifPresentOrElse(
    this::displayTrainDetails,
    () -> System.out.println("Train not found!")
);

πŸ”’ Security Features

  • Input validation for all user inputs
  • Password protection (stored as plain text for demo)
  • User authorization for ticket operations
  • PNR format validation
  • Thread-safe booking operations

πŸ› Error Handling

  • Comprehensive exception handling
  • Custom exceptions for booking scenarios
  • Input validation with user-friendly messages
  • Graceful error recovery

πŸ“Š System Statistics

The application tracks:

  • Total registered users
  • Total trains available
  • Total bookings made
  • Revenue generated
  • Seat utilization

πŸš€ Future Enhancements

  • Database integration (MySQL/PostgreSQL)
  • Web interface (Spring Boot)
  • Payment gateway integration
  • SMS/Email notifications
  • Admin panel for train management
  • Waitlist and RAC implementation
  • Multi-class booking (AC, Sleeper, etc.)

πŸ‘¨β€πŸ’» Development Notes

This project demonstrates:

  • Clean Code Principles: Well-structured, readable code
  • SOLID Principles: Single responsibility, dependency injection
  • Design Patterns: Service layer, Factory pattern for PNR generation
  • Java 8 Features: Extensive use of modern Java features
  • Error Handling: Robust exception management
  • Thread Safety: Synchronized critical sections

🀝 Contributing

This is a learning project demonstrating Core Java and Java 8 features. Feel free to:

  • Add new features
  • Improve error handling
  • Enhance UI/UX
  • Add unit tests
  • Optimize performance

Built with ❀️ using Core Java 8

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages