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.
- 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
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
- Java 11 or higher
- Maven 3.6 or higher
To build the project, run:
mvn clean compileTo run the application:
mvn compile
java -cp target/classes com.flight.service.FlightReservationAppTo run tests with detailed output:
mvn test -XWhen you run the application, you'll see a menu with the following options:
- Search for flights: Enter a destination and date to find available flights
- Book a flight: Book seats on a flight by providing your name, flight number, and number of seats
- View my reservations: View all reservations for a specific customer
- Exit: Exit the application
-
Search for flights:
- Enter destination:
New York - Enter date:
2024-06-16
- Enter destination:
-
Book a flight:
- Enter your name:
John Doe - Enter flight number:
AA101 - Enter number of seats:
2
- Enter your name:
-
View reservations:
- Enter your name:
John Doe
- Enter your name:
- 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
- Used
ArrayListfor 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
FlightServiceclass
- 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)
- 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
- 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
- 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
- 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
- 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
- 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
- For high-traffic scenarios:
- Caching layer (e.g., Redis) for frequently accessed flights
- Load balancing across multiple service instances
- Message queues for asynchronous processing
- Production system should include:
- Authentication and authorization
- Input sanitization to prevent injection attacks
- Rate limiting to prevent abuse
- Encryption for sensitive customer data
- 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
- For a production REST API:
- RESTful endpoints with proper HTTP methods
- Request/response DTOs
- API versioning
- Comprehensive API documentation (OpenAPI/Swagger)
- Production system should include:
- Application logging (e.g., Log4j, SLF4J)
- Metrics collection (e.g., Prometheus)
- Distributed tracing
- Error tracking and alerting
-
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(), andtoString()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
- 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
This project is created as part of a coding exercise.
Developed as a demonstration of Java programming skills, object-oriented design, and software engineering best practices.