public InventoryReport InventoryCars() { InventoryReport myInventoryReport = new InventoryReport(); int counter = new int(); foreach (var Car in CarList) { InventoryReportItem myReportItem = new InventoryReportItem(); myReportItem.CarNumber = (int)CarList.IndexOf(Car); myReportItem.CarType = Car.carType; if (Car.hybrid) { myReportItem.IsHybrid = true; } myReportItem.FuelType = Car.fuelType; myReportItem.Price = Car.currentPrice; myReportItem.FuelLevel = Car.fuelLevel; myReportItem.Price = Car.currentPrice; myInventoryReport.Inventory.Add(myReportItem); counter++; } myInventoryReport.NumberOfCars = counter; return(myInventoryReport); }
static void Main() { Program p = new Program(); string userSelection; bool stopRun = new bool(); while (!stopRun) { Menu(); userSelection = Console.ReadLine().ToUpper(); switch (userSelection) { case "0": stopRun = true; break; case "1": { string response = p.Create(Program.CarType.Pinto); Console.WriteLine(response); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } break; case "2": { string response = p.Create(Program.CarType.SemiTruck); Console.WriteLine(response); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } break; case "3": { string response = p.Create(Program.CarType.FunnyCar); Console.WriteLine(response); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } break; case "4": { string response = p.Create(Program.CarType.Pinto, true); Console.WriteLine(response); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } break; case "5": { string response = p.Create(Program.CarType.SemiTruck, true); Console.WriteLine(response); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } break; case "6": { string response = p.Create(Program.CarType.FunnyCar, true); Console.WriteLine(response); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } break; case "D": { Console.Write("Enter car number to drive: "); string tempString = Console.ReadLine(); if (isValidCarSelection(tempString, p.CarList.Count)) { string response = p.CarList[Int32.Parse(tempString)].Drive(); Console.WriteLine(response); Console.WriteLine("Press any key to contine..."); Console.ReadLine(); } else { Console.WriteLine("Invalid selection made! Returning to main menu..."); Console.WriteLine("Press any key to contine..."); Console.ReadLine(); } } break; case "F": { Console.Write("Enter car number to fuel: "); string tempString = Console.ReadLine(); if (isValidCarSelection(tempString, p.CarList.Count)) { FuelUpACar(ref p.CarList, Int32.Parse(tempString)); } else { Console.WriteLine("Invalid selection made! Returning to main menu..."); Console.ReadLine(); } } break; case "H": { Console.Write("Enter car number to honk: "); string tempString = Console.ReadLine(); if (isValidCarSelection(tempString, p.CarList.Count)) { string response = p.CarList[Int32.Parse(tempString)].Honk(); Console.WriteLine(response); Console.ReadLine(); } else { Console.WriteLine("Invalid Selection made! Returning to Main Menu..."); Console.ReadLine(); } } break; case "S": { Console.Write("Enter car number to drive: "); string tempString = Console.ReadLine(); if (isValidCarSelection(tempString, p.CarList.Count)) { p.CarList[Int32.Parse(tempString)].OnSale(); Console.WriteLine("Car has been discounted! Returning to main menu..."); Console.ReadLine(); } else { Console.WriteLine("Invalid selection made! Returning to main menu..."); Console.ReadLine(); } } break; case "L": InventoryReport myInventoryReport = p.InventoryCars(); foreach (InventoryReportItem iri in myInventoryReport.Inventory) { Console.WriteLine("Car number: " + iri.CarNumber); Console.WriteLine("Car type: " + iri.CarType); Console.WriteLine("Hybrid: " + (iri.IsHybrid ? "Yes" : "No")); Console.WriteLine("Fuel type: " + iri.FuelType); Console.WriteLine("Fuel Level: " + iri.FuelLevel); Console.WriteLine("Price: " + iri.Price); Console.WriteLine(String.Empty); } Console.WriteLine("Total Number of Cars in Lot: " + myInventoryReport.NumberOfCars); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); break; default: Console.WriteLine("Invalid Selection! Enter any key to continue...."); Console.ReadLine(); break; } } }