A comprehensive Java console-based application that simulates an online bus ticket booking platform. This project provides role-based access for both Administrators and Users, featuring bus management, seat reservation, ticket cancellation, and a simulated UPI payment gateway using Java Multithreading.
- Authentication: Users can register and log securely into the system.
- Search Buses: Search for available buses by entering the source, destination, and travel date.
- Seat Booking & Reservation:
- View real-time seat availability.
- Select specific seat numbers and enter passenger details.
- Booking Cancellation: Users can cancel their tickets (cancellation is allowed only if the departure time is more than 4 hours away).
- View Bookings: View a history of booked tickets.
- Download Ticket: Users can generate and download their e-tickets as a text file (
Ticket_RedBus.txt).
- Admin Dashboard: Secure login for administrators (credentials:
admin/admin). - Bus Management:
- Add new bus routes, specifying bus type (AC, AC Sleeper, Express, Normal), seat capacity, route, and timing.
- View all registered buses.
- Update existing bus schedules and details.
- Delete buses from the system.
- View All Bookings: Admins can monitor all tickets booked by users across the platform.
Note: The UPI payment feature in this console-based application is a simple object-oriented simulation built with standard Java classes. It does not integrate with any real UPI payment gateways or process actual financial transactions.
The application uses this simple setup to demonstrate the Producer-Consumer multithreading design pattern in an asynchronous payment processing context:
UpiPayClass (Shared Resource): Contains synchronizedput()(request payment) andget()(process payment) methods. It useswait()andnotify()for inter-thread communication, relying on a booleanrequestedflag to ensure synchronized data flow.- Producer Thread (
UserUpiPay): Represents the user initiating a payment request. It calls theput()method to submit the request. - Consumer Thread (
UserUpiPayResponse): Represents the payment gateway/server processing the request. It calls theget()method to accept and verify the transaction. - Synchronization: This implementation ensures that a payment response is generated only after a payment request is made, preventing race conditions and simulating an asynchronous transaction pipeline.
- Inheritance & Polymorphism: Abstract
Busclass acts as a base for specific bus types likeAcBus,AcSleeper,ExpressBus, andNormalBus. Dynamic method dispatch is used to calculate varying fare rates. - Encapsulation: Object properties (User, Ticket, Bus, Passenger) are strictly encapsulated using getter and setter methods.
- Abstraction: Complex business logic like booking algorithms and multithreaded payments are abstracted away from the user menu.
- Compile the Java files:
javac *.java - Run the main application:
java RedBusApp
- Use the interactive console menu to navigate as an Admin or a User.
RedBusApp.java- Application entry point.BookingService.java- Core business logic for searching and booking.Admin.java- Administrator functionalities.Bus.java(and subclasses) - Bus modeling.User.java- User profile and history management.Ticket.java- Ticket generation and file I/O operations.ProdConsumProb.java&Payment.java- Multithreading and payment interfaces.