public void MainMenu(ParkingLot parkingLot) { while (true) { Console.WriteLine("\n\n1. Park Vehicle"); Console.WriteLine("2. Unpark Vehicle"); Console.WriteLine("3. Display All Slots"); Console.WriteLine("4. Exit"); Console.WriteLine("Choose any option"); string choice = Console.ReadLine(); if (choice == "4") { break; } VehicleType vehicleType; ParkingSlot parkingSlot; switch (int.Parse(choice)) { case 1: parkingSlot = ReadVehicleDetail(out vehicleType); while (vehicleType == VehicleType.NONE) { parkingSlot = ReadVehicleDetail(out vehicleType); } if (parkingLot.GetNumberOfTwoWheelerParked() < TwoWheelerCapacity && vehicleType == VehicleType.TWO_WHEELER) { TwoWheelerCapacity++; parkingLot.ParkVehicle(parkingSlot); } else if (parkingLot.GetNumberOfFourWheelerParked() < FourWheelerCapacity && vehicleType == VehicleType.FOUR_WHEELER) { FourWheelerCapacity++; parkingLot.ParkVehicle(parkingSlot); } else if (parkingLot.GetNumberOfOtherVehicleParked() < OtherVehicleCapacity && vehicleType == VehicleType.OTHER) { OtherVehicleCapacity++; parkingLot.ParkVehicle(parkingSlot); } else { Error(SLOT_FULL_ERROR); } break; case 2: parkingSlot = ReadVehicleDetail(out vehicleType); bool unParked = false; while (vehicleType == VehicleType.NONE) { parkingSlot = ReadVehicleDetail(out vehicleType); } List <ParkingSlot> slotList = parkingLot.GetParkingSlotList(); foreach (ParkingSlot slot in slotList) { if (slot.GetVehicle().GetVehicleType() == vehicleType && slot.GetVehicle().GetVehicleNumber() == parkingSlot.GetVehicle().GetVehicleNumber()) { parkingLot.UnParkVehicle(slot); unParked = true; } } if (!unParked) { Error(VEHICLE_NOT_FOUND_ERROR); } break; case 3: DisplayAllSlots(parkingLot); break; default: Console.WriteLine("Invalid Choice"); break; } } }
public void DisplayAllSlots(ParkingLot parkingLot) { Console.WriteLine("\n\n****************** Parking Alloment Display ******************"); Console.WriteLine("Two Wheeler Parking Empty Slots = " + (TwoWheelerCapacity - parkingLot.GetNumberOfTwoWheelerParked())); Console.WriteLine("Four Wheeler Parking Empty Slots = " + (FourWheelerCapacity - parkingLot.GetNumberOfFourWheelerParked())); Console.WriteLine("Other Vehicle Parking Empty Slots = " + (OtherVehicleCapacity - parkingLot.GetNumberOfOtherVehicleParked())); List <ParkingSlot> slotList = parkingLot.GetParkingSlotList(); foreach (ParkingSlot slot in slotList) { Console.WriteLine("***** Slot Number : {0} *****", slot.GetSlotId()); Console.WriteLine("\nVehicleType {0}\t\tVehicle no. {1} ", slot.GetVehicle().GetVehicleType(), slot.GetVehicle().GetVehicleNumber()); } Console.WriteLine("\n\n"); }