Pergunta de entrevista da empresa FPL Technologies

write a java program to book a slot for KYC validation, show available slots to user

Resposta da entrevista

Sigiloso

12 de out. de 2024

import java.util.ArrayList; import java.util.List; import java.util.Scanner; class SlotBooking { private List availableSlots; private List bookedSlots; public SlotBooking() { availableSlots = new ArrayList(); bookedSlots = new ArrayList(); // Initialize some slots for KYC validation availableSlots.add("10:00 AM - 10:30 AM"); availableSlots.add("11:00 AM - 11:30 AM"); availableSlots.add("12:00 PM - 12:30 PM"); availableSlots.add("02:00 PM - 02:30 PM"); availableSlots.add("03:00 PM - 03:30 PM"); availableSlots.add("04:00 PM - 04:30 PM"); } // Display available slots public void showAvailableSlots() { if (availableSlots.isEmpty()) { System.out.println("No available slots. All slots have been booked."); } else { System.out.println("Available slots:"); for (int i = 0; i availableSlots.size()) { System.out.println("Invalid slot selection."); return; } // Slot booking String bookedSlot = availableSlots.get(slotNumber - 1); bookedSlots.add(bookedSlot); availableSlots.remove(slotNumber - 1); System.out.println("You have successfully booked the slot: " + bookedSlot); } // Show booked slots public void showBookedSlots() { if (bookedSlots.isEmpty()) { System.out.println("No slots have been booked yet."); } else { System.out.println("Booked slots:"); for (String slot : bookedSlots) { System.out.println(slot); } } } } public class KYCSlotBookingApp { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); SlotBooking slotBooking = new SlotBooking(); while (true) { System.out.println("\nKYC Slot Booking System"); System.out.println("1. Show available slots"); System.out.println("2. Book a slot"); System.out.println("3. Show booked slots"); System.out.println("4. Exit"); System.out.print("Choose an option: "); int choice = scanner.nextInt(); switch (choice) { case 1: slotBooking.showAvailableSlots(); break; case 2: slotBooking.showAvailableSlots(); if (!slotBooking.availableSlots.isEmpty()) { System.out.print("Enter slot number to book: "); int slotNumber = scanner.nextInt(); slotBooking.bookSlot(slotNumber); } break; case 3: slotBooking.showBookedSlots(); break; case 4: System.out.println("Exiting the system..."); scanner.close(); return; default: System.out.println("Invalid choice, please try again."); } } } }