|
| 1 | +import java.util.*; |
| 2 | + |
| 3 | +public class Admin extends AMS { |
| 4 | + static Scanner sc = new Scanner(System.in); |
| 5 | + |
| 6 | + public static void createCarrier() { |
| 7 | + System.out.print("Enter the Carrier Name: "); |
| 8 | + String carrierName = sc.nextLine().trim(); |
| 9 | + |
| 10 | + System.out.print("Enter Discount for 30 Days Advance Booking: "); |
| 11 | + int discount30Days = sc.nextInt(); |
| 12 | + |
| 13 | + System.out.print("Enter Discount for 60 Days Advance Booking: "); |
| 14 | + int discount60Days = sc.nextInt(); |
| 15 | + |
| 16 | + System.out.print("Enter Discount for 90 Days Advance Booking: "); |
| 17 | + int discount90Days = sc.nextInt(); |
| 18 | + |
| 19 | + System.out.print("Enter Bulk Booking Discount: "); |
| 20 | + int bulkBooking = sc.nextInt(); |
| 21 | + |
| 22 | + System.out.print("Enter Refund for Ticket Cancellation (2 Days Before): "); |
| 23 | + int refund2Days = sc.nextInt(); |
| 24 | + |
| 25 | + System.out.print("Enter Refund for Ticket Cancellation (10 Days Before): "); |
| 26 | + int refund10Days = sc.nextInt(); |
| 27 | + |
| 28 | + System.out.print("Enter Refund for Ticket Cancellation (20 Days Before): "); |
| 29 | + int refund20Days = sc.nextInt(); |
| 30 | + |
| 31 | + System.out.print("Enter Silver User Discount: "); |
| 32 | + int silverDiscount = sc.nextInt(); |
| 33 | + |
| 34 | + System.out.print("Enter Gold User Discount: "); |
| 35 | + int goldDiscount = sc.nextInt(); |
| 36 | + |
| 37 | + System.out.print("Enter Platinum User Discount: "); |
| 38 | + int platinumDiscount = sc.nextInt(); |
| 39 | + try { |
| 40 | + int carrierId = carrierMapList.size() + 1; |
| 41 | + |
| 42 | + Carrier newCarrier = new Carrier(carrierId, carrierName, discount30Days, discount60Days, discount90Days, |
| 43 | + bulkBooking, |
| 44 | + refund2Days, refund10Days, refund20Days, silverDiscount, goldDiscount, platinumDiscount); |
| 45 | + carrierMapList.put(carrierId, newCarrier); |
| 46 | + System.out.println("Carrier Added Successfully"); |
| 47 | + } catch (Exception e) { |
| 48 | + System.out.println("Encountered issue while saving carrier information. Please check the data and try again"); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + public static void editCarrier() { |
| 53 | + System.out.print("Enter Carrier ID: "); |
| 54 | + int carrierId = sc.nextInt(); |
| 55 | + sc.nextLine(); |
| 56 | + |
| 57 | + if (!carrierMapList.containsKey(carrierId)) |
| 58 | + System.out |
| 59 | + .println("Either the data is incorrect or no Carrier informationis availabe for tha given Ca rrier ID "); |
| 60 | + |
| 61 | + System.out.print("Enter new Carrier Name: "); |
| 62 | + String carrierName = sc.nextLine(); |
| 63 | + |
| 64 | + System.out.print("Enter new Discount for 30 Days Advance Booking: "); |
| 65 | + int discount30Days = sc.nextInt(); |
| 66 | + |
| 67 | + System.out.print("Enter new Discount for 60 Days Advance Booking: "); |
| 68 | + int discount60Days = sc.nextInt(); |
| 69 | + |
| 70 | + System.out.print("Enter new Discount for 90 Days Advance Booking: "); |
| 71 | + int discount90Days = sc.nextInt(); |
| 72 | + |
| 73 | + System.out.print("Enter new Bulk Booking Discount: "); |
| 74 | + int bulkBooking = sc.nextInt(); |
| 75 | + |
| 76 | + System.out.print("Enter new Refund for Ticket Cancellation (2 Days Before): "); |
| 77 | + int refund2Days = sc.nextInt(); |
| 78 | + |
| 79 | + System.out.print("Enter new Refund for Ticket Cancellation (10 Days Before): "); |
| 80 | + int refund10Days = sc.nextInt(); |
| 81 | + |
| 82 | + System.out.print("Enter new Refund for Ticket Cancellation (20 Days Before): "); |
| 83 | + int refund20Days = sc.nextInt(); |
| 84 | + |
| 85 | + System.out.print("Enter new Silver User Discount: "); |
| 86 | + int silverDiscount = sc.nextInt(); |
| 87 | + |
| 88 | + System.out.print("Enter new Gold User Discount: "); |
| 89 | + int goldDiscount = sc.nextInt(); |
| 90 | + |
| 91 | + System.out.print("Enter new Platinum User Discount: "); |
| 92 | + int platinumDiscount = sc.nextInt(); |
| 93 | + try { |
| 94 | + Carrier newCarrier = new Carrier(carrierId, carrierName, discount30Days, discount60Days, discount90Days, |
| 95 | + bulkBooking, |
| 96 | + refund2Days, refund10Days, refund20Days, silverDiscount, goldDiscount, platinumDiscount); |
| 97 | + carrierMapList.put(carrierId, newCarrier); |
| 98 | + System.out.println("Carrier Added Successfully"); |
| 99 | + } catch (Exception e) { |
| 100 | + System.out.println("Encountered issue while saving carrier information. Please check the data and try again"); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + public static void displayCarrier() { |
| 105 | + if (carrierMapList.isEmpty()) { |
| 106 | + System.out.println("\nNo Customers Registered Yet."); |
| 107 | + } else { |
| 108 | + System.out.println("\nList of Customers:"); |
| 109 | + for (Map.Entry<Integer, Carrier> map : carrierMapList.entrySet()) { |
| 110 | + System.out.println( |
| 111 | + "Carrier ID: " + map.getValue().getCarrierId() + |
| 112 | + " | Name: " + map.getValue().getCarrierName() |
| 113 | + ); |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + public static boolean adminMenu() { |
| 119 | + int choose_menu = 0; |
| 120 | + do { |
| 121 | + System.out.print("-------------------------------------------------------------------"); |
| 122 | + System.out.print( |
| 123 | + "\nAdmin Menu\n1.Add Carrier\n2.Edit Carrier Details by CarrierId\n3.Remove Carrier by Id\n4.Flight Cancellation - Refund Price Calculation\n5.Exit Admin\n6.Exit AMS"); |
| 124 | + System.out.print("\n-------------------------------------------------------------------"); |
| 125 | + System.out.print("\nEnter the operation : "); |
| 126 | + choose_menu = sc.nextInt(); |
| 127 | + sc.nextLine(); |
| 128 | + switch (choose_menu) { |
| 129 | + case 1: |
| 130 | + System.out.println("Add Carrier"); |
| 131 | + createCarrier(); |
| 132 | + break; |
| 133 | + case 2: |
| 134 | + System.out.println("Edit Carrier Details by CarrierId"); |
| 135 | + editCarrier(); |
| 136 | + break; |
| 137 | + case 3: |
| 138 | + System.out.println("Remove Carrier by Id"); |
| 139 | + break; |
| 140 | + case 4: |
| 141 | + System.out.println("Flight Cancellation - Refund Price Calculation"); |
| 142 | + displayCarrier(); |
| 143 | + break; |
| 144 | + case 5: |
| 145 | + System.out.println("Exit Admin"); |
| 146 | + break; |
| 147 | + case 6: |
| 148 | + System.out.println("Exit AMS"); |
| 149 | + return true; |
| 150 | + default: |
| 151 | + System.out.print("Invalid"); |
| 152 | + } |
| 153 | + } while (choose_menu != 5); |
| 154 | + return false; |
| 155 | + } |
| 156 | +} |
0 commit comments