private static void IntantiateObjects(out Car car1, out Car car2, out Car car3, out UsedCar car4, out UsedCar car5, out UsedCar car6) { //Instantiate car1 = new Car("Nikolai", "Model S", 2017, 54999.90); car2 = new Car("Fourd", "Escapade", 2017, 31999.90); car3 = new Car("Chewie", "Vette", 2017, 44989.95); car4 = new UsedCar("Hyonda", "Prior", 2015, 14795.5, 35987); car5 = new UsedCar("GC", "Chirpus", 2013, 8500, 12345); car6 = new UsedCar("GC", "Witherell", 2016, 14450, 3500); }
static void Main(string[] args) { Car newcar1 = new Car("Chevy", "Impala", 2017, 4000); Car newcar2 = new Car("Jeep", "Compass", 2014, 5000); Car newcar3 = new Car("Madza", "Cx5", 2017, 9000); UsedCar usedCar1 = new UsedCar("ford", "Escape", 2016, 7000, 23840); UsedCar usedCar2 = new UsedCar("Toyota", "Highlander", 2018, 10000, 40100); UsedCar usedCar3 = new UsedCar("Nissan", "Altima", 2010, 8000, 57768); List <Car> carList = new List <Car>() { newcar1, newcar2, newcar3, usedCar1, usedCar2, usedCar3 }; foreach (Car singleCar in carList) { singleCar.PrintInfo(); } Console.WriteLine(" Which car would you like? Enter a number between 0-5"); int choice = int.Parse(Console.ReadLine()); carList[choice].PrintInfo(); Console.WriteLine(" Would you like to buy a car? y/n"); string select = Console.ReadLine().ToLower(); while (true) { if (select == "y") { Console.WriteLine(" Excellent! Our finance department will be in touch shortly. Thanks!"); break; } else { Console.WriteLine(" Have a great day!"); } Console.ReadLine(); } }
static void Main(string[] args) { List <Car> cars = new List <Car>(); Car c1 = new UsedCar(2011, "Ford", "Taurus", 20000, 199000); Car c2 = new Car(2019, "Chevy", "Malibu", 10000); Car c3 = new UsedCar(2011, "Lamborghini", "Aventador", 345000, 1200); Car c4 = new Car(2019, "Ferrari", "Italia", 400000); Car c5 = new UsedCar(2019, "Bentley", "Mulsanne", 500000, 1234); Car c6 = new Car(2019, "Toyota", "Camry", 200000); cars.Add(c1); cars.Add(c2); cars.Add(c3); cars.Add(c4); cars.Add(c5); cars.Add(c6); Console.WriteLine("Which car do you want to select?Enter a number: 1- 6"); for (int k = 0; k < cars.Count; k++) { int t = k + 1; Car nn = cars[k]; Console.WriteLine($"{t} {cars[k]}"); } int s = int.Parse(Console.ReadLine()); if (s == 1) { Console.WriteLine(cars[0]); } else if (s == 2) { Console.WriteLine(cars[1]); } else if (s == 3) { Console.WriteLine(cars[2]); } else if (s == 4) { Console.WriteLine(cars[3]); } else if (s == 5) { Console.WriteLine(cars[4]); } else if (s == 6) { Console.WriteLine(cars[5]); } Console.WriteLine("Would you like to buy the car?"); string answer = Console.ReadLine().ToLower(); if (answer == "y") { cars.RemoveAt(s - 1); } else if (answer == "n") { Console.WriteLine("Thank you"); } for (int k = 0; k < cars.Count; k++) { int t = k + 1; Car nn = cars[k]; Console.WriteLine($"{t} {cars[k]}"); } }