static void Main(string[] args) { var newCar = new Vehicle() { Name = "Baleno", Model = "TDi", Speed = 120 }; var newTruck = new Vehicle() { Name = "TATA", Model = "H22x", Speed = 90 }; var newBike = new TwoWheeler() { Name = "Apache", Model = "RtR", Speed = 100 }; ArrayList vehicles = new ArrayList { newCar, newTruck, newBike }; Console.WriteLine("Enumerating through the list contents and using tostring method for printing."); foreach (var vehicle in vehicles) { Console.WriteLine(vehicle.ToString()); } Console.WriteLine(""); Console.WriteLine("Gettting the list element using indexes"); for (int i = 0; i < vehicles.Count; i++) { Console.WriteLine("Name : {0}, Model : {1}, Speed {2}", ((Vehicle)vehicles[i]).Name, ((Vehicle)vehicles[i]).Model, ((Vehicle)vehicles[i]).Speed); Console.WriteLine("The Name of the viehicle : {0} is modified to : {1}", ((Vehicle)vehicles[i]).Name, ((Vehicle)vehicles[i]).Name = "X"); } Console.WriteLine(""); Console.WriteLine("Calling ToString from object"); Console.WriteLine(Convert.ToString(newBike)); Console.WriteLine(Convert.ToString(newCar)); }
private void btn_next_Click(object sender, EventArgs e) { bool isControlThere = pnl_container.Controls.Count > 0; if (isControlThere) { pnl_container.Controls.Clear(); } TwoWheeler tv = new TwoWheeler(); tv.TopLevel = false; tv.FormBorderStyle = FormBorderStyle.None; pnl_container.Controls.Add(tv); tv.Visible = true; }
public static void Main() { while (true) { Display Display = new Display(); Functions functions = new Functions(); List <Ticket> tickets = new List <Ticket>(); IParkingService ParkingServices = new ParkingSevice(); ITicketService ticketService = new TicketService(); int option; string regionalCode; Display.Print("WELCOME TO ABCD PARKING LOT"); Display.Print("******************************************"); Display.Print("please enter number of slots for 2 wheeler"); int twoWheeler = functions.Input(); Display.Print("please enter number of slots for 4 wheeler"); int fourWheeler = functions.Input(); Display.Print("please enter number of slots for heavy vehicle"); int heavyVehicle = functions.Input(); Display.Print("do you want to enter the Regional Code\n\t1.yes\n\t2.no"); option = functions.Input(); switch (option) { case 1: Display.Print("please enter a Regional Code:"); regionalCode = Display.Scan(); functions.Regionalcode(regionalCode); break; default: regionalCode = null; break; } ParkingServices.InitializeParkingLot(twoWheeler, fourWheeler, heavyVehicle); bool Exit = false; do { Display.Print("select a option\n\t1.park\n\t2.Un-park\n\t3.Display status of all slots\n\t4.Exit(Re-Initialize)"); option = functions.Input(); switch (option) { case 1: Display.Print("please enter the valid details of the vehicle"); Vehicle vehicle = new Vehicle(); Display.Print("Choose the type of vehicle\n\t1.2 wheeler\n\t2.4 wheeler\n\t3.heavy vehicle\n\t"); int choice = functions.Input(); var Type = (VehicleModel)choice; List <Slot> AvailableSlots = ParkingServices.GetAvailableSlots(Type); if (AvailableSlots != null) { bool validSlot = false; //FOR EXITING THE LOOP do { foreach (Slot thisSlot in AvailableSlots) { Console.WriteLine($"slot-{ thisSlot.Id }"); } Display.Print("Please choose a slot number"); int slotNumber = functions.Input(); Slot SelectedSlot = AvailableSlots.Find(slot => slot.Id == slotNumber); bool validity = false; if (SelectedSlot != null) { do { Display.Print("Please enter the vehicle number"); string number = Display.Scan(); var VehicleNumber = functions.vehicleNumber(number, regionalCode); switch (choice) { case 1: vehicle = new TwoWheeler(VehicleNumber); break; case 2: vehicle = new FourWheeler(VehicleNumber); break; case 3: vehicle = new HeavyVehicle(VehicleNumber); break; default: break; } Validations validation = new Validations(); if (validation.IsValidVehicleNumber(vehicle.VehicleNumber) == true) { bool isSame = ParkingServices.CheckSimialarVehicleNo(vehicle.VehicleNumber); if (isSame == false) { validity = true; } else { Display.Print("The Vehicle numberis already parked in another slot"); Display.Print("******************************************"); } //*********there is still a chance that two vehicles can be parked with same number } else { Display.Print("Please check the format of the vehicle number"); Display.Print("******************************************"); validity = false; } }while (validity == false); SelectedSlot.ParkedVehicle = vehicle; Ticket ticket = ticketService.GenerateTicket(slotNumber, vehicle.VehicleNumber); ParkingServices.Park(slotNumber, vehicle.VehicleNumber); ticketService.UpdateTicketList(ticket); functions.Parked(SelectedSlot.Id); Display.Print("******************************************"); Console.WriteLine($"Ticket Id:{ticket.Id}\nVehicle Number:{SelectedSlot.ParkedVehicle.VehicleNumber}\nSlot Number:{SelectedSlot.Id}\nIn-Time:{ticket.InTime}"); Display.Print("******************************************"); validSlot = true; } else { functions.Invalid(); } }while (validSlot == false); } else { functions.NoSlot(); } break; case 2: while (true) { int ticketCount = ticketService.GetTicketCount(); if (ticketCount != 0) { bool validSlot = false; do { Display.Print("Please enter the slot Id"); int Id = functions.Input(); Ticket SelectedTicket = ticketService.GetTicket(Id); if (SelectedTicket != null) { Slot slot = ParkingServices.GetSlot(SelectedTicket.SlotNumber); if (slot.Availability == Status.OCCUPIED) { SelectedTicket.OutTime = DateTime.Now; ParkingServices.UnPark(SelectedTicket.SlotNumber); Display.Print("******************************************"); Display.Print("The vehicle is unparked"); Console.WriteLine($"Ticket Id:{SelectedTicket.Id}\nVehicle Number:{SelectedTicket.VehicleNumber}\nSlot Number:{SelectedTicket.SlotNumber}\nIn-Time:{SelectedTicket.InTime}\nOut-Time:{SelectedTicket.OutTime}"); Display.Print("******************************************"); } else { Display.Print("the vehicle is already unparked from the slot"); Display.Print("******************************************"); } validSlot = true; } else { Display.Print("enter a valid slot id"); } }while (validSlot == false); break; } else { Display.Print("no tickets are generated yet"); break; } } break; case 3: List <Slot> Slots = ParkingServices.GetSlots(); foreach (Slot slot in Slots) { string vehicleNumber = ((slot.ParkedVehicle == null) ? "-----" : slot.ParkedVehicle.VehicleNumber); Console.WriteLine($"slot:{slot.Id} type:{slot.Type} status:{Convert.ToString(slot.Availability)} vehiclePArked:{vehicleNumber}"); } Display.Print("******************************************"); break; case 4: Exit = true; break; default: Display.Print("please select a valid option"); Display.Print("******************************************"); break; } }while (Exit == false); } }
public VehicleClient(VehicleFactory factory, string type) { bike = factory.GetTwoWheeler(type); car = factory.GetFourWheeler(type); }