importjava.util.ArrayList;importjava.util.Scanner;classBooking{String name;int seatNo;// Add more fields as neededpublicBooking(String name,int seatNo){this.name = name;this.seatNo = seatNo;// Initialize other fields as needed}}classBusBookingSystem{privateArrayList<Booking> bookings =newArrayList<>();publicvoidbookSeat(){Scanner scanner =newScanner(System.in);System.out.print("Enter name: ");String name = scanner.nextLine();System.out.print("Enter seat number: ");int seatNo = scanner.nextInt();
scanner.nextLine();// Consume the newline character// Add more input fields as neededBooking newBooking =newBooking(name, seatNo);
bookings.add(newBooking);System.out.println("Seat booked successfully.");}publicvoidviewReservations(){if(bookings.isEmpty()){System.out.println("No reservations made yet.");return;}System.out.println("All reservations:");System.out.println("Seat No.\tName");for(Booking booking : bookings){System.out.println(booking.seatNo +"\t\t"+ booking.name);}}publicvoideditReservation(){Scanner scanner =newScanner(System.in);System.out.print("Enter seat number to edit: ");int seatToEdit = scanner.nextInt();
scanner.nextLine();// Consume the newline characterboolean found =false;for(Booking booking : bookings){if(booking.seatNo == seatToEdit){System.out.print("Enter new name: ");
booking.name = scanner.nextLine();// Add more fields to edit as neededSystem.out.println("Reservation edited successfully.");
found =true;break;}}if(!found){System.out.println("Reservation not found.");}}publicvoidprintTicket(){Scanner scanner =newScanner(System.in);System.out.print("Enter seat number to print ticket: ");int seatToPrint = scanner.nextInt();
scanner.nextLine();// Consume the newline characterboolean found =false;for(Booking booking : bookings){if(booking.seatNo == seatToPrint){System.out.println("Ticket for Seat No. "+ booking.seatNo);System.out.println("Passenger Name: "+ booking.name);// Add more fields to print as needed
found =true;break;}}if(!found){System.out.println("Reservation not found.");}}}publicclassMain{publicstaticvoidmain(String[] args){BusBookingSystem system =newBusBookingSystem();Scanner scanner =newScanner(System.in);int choice;do{System.out.println("\nMini Bus Booking System");System.out.println("1. Book a seat");System.out.println("2. View reservations");System.out.println("3. Edit a reservation");System.out.println("4. Print a ticket");System.out.println("5. Exit");System.out.print("Enter your choice: ");
choice = scanner.nextInt();
scanner.nextLine();// Consume the newline characterswitch(choice){case1:
system.bookSeat();break;case2:
system.viewReservations();break;case3:
system.editReservation();break;case4:
system.printTicket();break;case5:System.out.println("Exiting...");break;default:System.out.println("Invalid choice. Please enter a valid option.");}}while(choice !=5);}}