Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Flight Reservation System

A Java-based flight reservation system that allows users to search for available flights, book flights, and manage their reservations through a console-based interface.

Features

  • Flight Search: Search for available flights by destination and date
  • Flight Booking: Book seats on available flights with validation
  • Reservation Management: View all reservations for a customer
  • Data Validation: Comprehensive input validation and error handling
  • Unit Testing: Extensive test coverage with JUnit 5

Project Structure

flight-reservation-system/
├── pom.xml
├── README.md
└── src/
    ├── main/
    │   └── java/
    │       └── com/
    │           └── flightreservation/
    │               ├── Flight.java
    │               ├── Reservation.java
    │               ├── FlightService.java
    │               └── FlightReservationApp.java
    └── test/
        └── java/
            └── com/
                └── flightreservation/
                    ├── FlightTest.java
                    ├── ReservationTest.java
                    └── FlightServiceTest.java

Requirements

  • Java 11 or higher
  • Maven 3.6 or higher

Building the Project

To build the project, run:

mvn clean compile

Running the Application

To run the application:

mvn compile
java -cp target/classes com.flight.service.FlightReservationApp

Running Tests

To run tests with detailed output:

mvn test -X

Usage

When you run the application, you'll see a menu with the following options:

  1. Search for flights: Enter a destination and date to find available flights
  2. Book a flight: Book seats on a flight by providing your name, flight number, and number of seats
  3. View my reservations: View all reservations for a specific customer
  4. Exit: Exit the application

Example Usage

  1. Search for flights:

    • Enter destination: New York
    • Enter date: 2024-06-16
  2. Book a flight:

    • Enter your name: John Doe
    • Enter flight number: AA101
    • Enter number of seats: 2
  3. View reservations:

    • Enter your name: John Doe

Design Decisions

1. Object-Oriented Design

  • Flight Class: Encapsulates flight data with validation in the constructor
  • Reservation Class: Represents a booking relationship between a customer and a flight
  • FlightService Class: Central service layer managing business logic and data operations
  • FlightReservationApp Class: Handles user interaction and presentation logic

2. Data Management

  • Used ArrayList for in-memory storage of flights and reservations
  • Data is stored during application execution but does not persist after shutdown
  • Flight and reservation lists are encapsulated within the FlightService class

3. Validation and Error Handling

  • Input validation at multiple levels:
    • Constructor validation for domain objects
    • Service method validation for business rules
    • User input validation in the console interface
  • Clear error messages guide users when validation fails
  • Prevents invalid operations (e.g., booking more seats than available)

4. Thread Safety Considerations

  • The current implementation is not thread-safe, which is acceptable for a single-user console application
  • In a production multi-threaded environment, synchronization mechanisms would be needed

5. Immutability vs Mutability

  • Flight objects are mutable (seats can be reduced), which is necessary for the booking functionality
  • Reservation objects are immutable once created, ensuring data integrity
  • Used defensive copying when returning lists from service methods

6. Search Functionality

  • Case-insensitive destination matching for better user experience
  • Date matching considers only the date portion, ignoring time
  • Results are sorted by departure time for better usability
  • Only returns flights with available seats

7. Testing Strategy

  • Comprehensive unit tests covering:
    • Happy path scenarios
    • Edge cases (zero seats, negative values, null inputs)
    • Boundary conditions (booking exact available seats)
    • Error conditions (booking more than available, invalid inputs)
  • Tests are isolated and independent
  • High test coverage for critical business logic

Real-Life Considerations

1. Concurrency

  • In a real-world system, concurrent booking requests would require:
    • Database transactions with proper isolation levels
    • Optimistic or pessimistic locking mechanisms
    • Distributed locking for microservices architectures

2. Data Persistence

  • Current implementation uses in-memory storage
  • Production system would require:
    • Database integration (e.g., PostgreSQL, MySQL)
    • ORM framework (e.g., Hibernate, JPA)
    • Data migration and backup strategies

3. Scalability

  • For high-traffic scenarios:
    • Caching layer (e.g., Redis) for frequently accessed flights
    • Load balancing across multiple service instances
    • Message queues for asynchronous processing

4. Security

  • Production system should include:
    • Authentication and authorization
    • Input sanitization to prevent injection attacks
    • Rate limiting to prevent abuse
    • Encryption for sensitive customer data

5. Business Rules

  • Additional features to consider:
    • Cancellation and refund policies
    • Seat selection (window, aisle, etc.)
    • Multiple passenger booking
    • Payment processing integration
    • Email notifications
    • Waitlist functionality when flights are full

6. API Design

  • For a production REST API:
    • RESTful endpoints with proper HTTP methods
    • Request/response DTOs
    • API versioning
    • Comprehensive API documentation (OpenAPI/Swagger)

7. Monitoring and Logging

  • Production system should include:
    • Application logging (e.g., Log4j, SLF4J)
    • Metrics collection (e.g., Prometheus)
    • Distributed tracing
    • Error tracking and alerting

Code Quality

  • Java Best Practices:

    • Proper encapsulation with private fields and public getters
    • Meaningful variable and method names
    • JavaDoc comments for public methods
    • Proper exception handling
    • Override equals(), hashCode(), and toString() where appropriate
  • SOLID Principles:

    • Single Responsibility: Each class has a clear, single purpose
    • Open/Closed: Classes are open for extension but closed for modification
    • Dependency Inversion: Service layer abstracts data management

Future Enhancements

  • Add flight cancellation functionality
  • Implement seat selection (window, aisle, middle)
  • Add payment processing simulation
  • Support for multiple passengers in a single booking
  • Export reservations to PDF
  • Add admin interface for managing flights
  • Implement waitlist functionality

License

This project is created as part of a coding exercise.

Author

Developed as a demonstration of Java programming skills, object-oriented design, and software engineering best practices.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages