static void Main(string[] args) { Car car1 = new Car("Ford", "Fusion", 2013, 19800); Car car2 = new Car("Toyota", "Prius", 2018, 24370); Car car3 = new Car("Dodge", "Durango", 2016, 22100); UsedCar used1 = new UsedCar("Ford", "F150", 2004, 7300, 76405.2); UsedCar used2 = new UsedCar("Hyundai", "Sonata", 2011, 6700, 67130); UsedCar used3 = new UsedCar("Ford", "Flex", 2013, 16400, 24607); List <Car> cars = new List <Car>() { car1, car2, car3, used1, used2, used3 }; CarLot carLot = new CarLot(cars); while (true) { Console.WriteLine($"#: {"Year",-15}{"Model",-15}{"Make",-15}{"Price",-15}{"Mileage (When used)"}"); Console.WriteLine("================================================================================="); carLot.ListCars(cars); while (true) { string addBuyReplace = Validator.AddBuyReplaceValidator("Would you like to add a car to the list, replace a car, or buy a car? (Please enter 'add', 'replace', or 'buy')", "That was not add, buy, or replace. Please enter one of those three options"); if (addBuyReplace.ToLower() == "buy") { int carSelection = Validator.ListChoiceValidator("Select which car you would like: ", $"Not a valid input! Please input between 1 and {carLot.Lot.Count}", $"Not within range. Please enter a number between 1 and {carLot.Lot.Count}", carLot.Lot.Count); Console.WriteLine($"{"Year",-15}{"Model",-15}{"Make",-15}{"Price",-15}{"Mileage (When used)"}"); Console.WriteLine("================================================================================="); Console.WriteLine(carLot.Lot[carSelection - 1].ToString()); string choice = Validator.AddChoiceValidator("Would you like to buy this car? (Y/N): ", "That wasnt a yes or no, so please be clear! Enter (Y/N or yes/no): "); if (choice.ToLower() == "y" | choice.ToLower() == "yes") { carLot.RemoveCar(carSelection); } break; } else if (addBuyReplace.ToLower() == "replace") { int carSelection = Validator.ListChoiceValidator("Select which car you would like to replace: ", $"Not a valid input! Please input between 1 and {carLot.Lot.Count}", $"Not within range. Please enter a number between 1 and {carLot.Lot.Count}", carLot.Lot.Count); Console.WriteLine($"{"Year",-15}{"Model",-15}{"Make",-15}{"Price",-15}{"Mileage (When used)"}"); Console.WriteLine("================================================================================="); Console.WriteLine(carLot.Lot[carSelection - 1].ToString()); carLot.ReplaceCar(cars, carSelection); break; } else { carLot.Lot.Add(carLot.AddCar()); break; } } string continueChoice = Validator.ContinueChoiceValidator("Would you like to see the list of cars?: ", "That wasn't a yes or no, please be clear! Enter (Y/N or yes/no): "); if (continueChoice.ToLower() == "y" | continueChoice.ToLower() == "yes") { Console.Clear(); } else { break; } } Console.ReadKey(); #region AddCarLoop //while (true) //{ // Car temp = new Car(); // temp.Make = Validator.MakeValidator("Please enter the make of the car (eg. Ford):", "Sorry, that was an invalid input. Please enter the make of the car (eg. Ford):"); // temp.Model = Validator.ModelValidator("Please enter the model of the car (eg. F150):", "Sorry, that was an invalid input. Please enter the model of the car (eg. F150):"); // temp.Year = Validator.YearValidator("Please enter the year of the car (eg. 2005):", "Sorry, that is not a valid year. Please enter the year of the car (1900 to 2019):"); // temp.Price = Validator.PriceValidator("Please enter the price of the car:", "Not a valid price. Please enter the price of the car."); // cars.Add(temp); // string choice = Validator.AddChoiceValidator("Would you like to add another car? (Y/N): ", "That wasnt a yes or no, so please be clear! Enter (Y/N or yes/no): "); // if (choice.ToLower() == "n") // break; //} //Console.WriteLine($"{"Year",-15}{"Model",-15}{"Make",-15}{"Price in dollars",-20}"); //Console.WriteLine("============================================================="); //foreach (Car c in cars) //{ // Console.WriteLine(c.ToString()); //} #endregion }
public static void Main(string[] args) { // List of Cars you build List <Car> cars = new List <Car>(); // empty list you're adding to // create objects because not asking for input, and the vars are initialized with data below // can list a string, but will pass an int so user can select vehicle by number on list to get info Car c1 = new Car("Ford", "Focus", 2017, 12000); Car c2 = new Car("Chevy", "Impala", 2017, 15000); Car c3 = new Car("GMC", "Terrain", 2017, 22000); UsedCar u1 = new UsedCar("Cadillac", "XT5", 2017, 35000, 35987.6); UsedCar u2 = new UsedCar("BMW", "i8", 2017, 90000, 50432.8); UsedCar u3 = new UsedCar("Range Rover", "Sport", 2017, 82000, 60342.8); cars.Add(c1); cars.Add(c2); cars.Add(c3); cars.Add(u1); cars.Add(u2); cars.Add(u3); CarLot carlotlist = new CarLot(cars); // create CarList from Car list info while (true) { Console.Clear(); Console.WriteLine("Current Inventory: "); if (carlotlist.Lot.Count() == 0) //newlist, then Class, then listing out the number of availible cars { Console.WriteLine("Sorry, we're sold out!"); } else // if they choose a number of the inventory greater than 0 { foreach (Car c in carlotlist.Lot) // for each listed item that was stored, print info input { Console.WriteLine($"{carlotlist.Lot.IndexOf(c) + 1,1}: {c.Year,-5} {c.Make,-5} {c.Model,-5}"); } Console.WriteLine("================================="); Console.WriteLine("Please choose a vehicle number from the list above: "); } if (carlotlist.Lot.Count() > 0) //if you still have inventory //.count tells how many in the list { try { string input = Console.ReadLine(); foreach (Car c in carlotlist.Lot) // for each listed item that was stored, print info input { if (carlotlist.Lot.IndexOf(c) + 1 == int.Parse(input)) // +1 becaues not index 0 { c.PrintInfo(); Console.WriteLine(); carlotlist.Lot.RemoveAt(int.Parse(input) - 1); } Console.WriteLine("Would you like to view another car, or add a new vehicle to inventory? Choose 'view' or 'add':"); string userChoice = Console.ReadLine(); // takes in user answer of view or add { if (userChoice.ToLower() == "view") { continue; } if (userChoice.ToLower() == "add") { carlotlist.Lot.Insert(int.Parse(input) - 1); } } } } catch (Exception e) { Console.ReadKey();//if no add an exception } } Console.WriteLine("Do you want to view another car? Y/N"); string choice = Console.ReadLine(); if (choice.ToLower() == "n") //so it doesn't matter if it's lower case or uppper case input { break; } Console.Clear(); // print car list method? Console.WriteLine("Current Inventory: "); Console.WriteLine("Make Model Year Price Mileage"); Console.WriteLine("===== ===== ===== ===== ====="); foreach (Car c in carlotlist.Lot) // for each listed item that was stored, print info input { c.PrintInfo(); } } }