public static void UserAddedCar()
        {
            Console.WriteLine("Enter the make:");
            var makeofCar = Console.ReadLine();

            Console.WriteLine("Enter the model:");
            var modelofCar = Console.ReadLine();

            Console.WriteLine("Enter the year:");
            int.TryParse(Console.ReadLine(), out int yearofCar);


            Console.WriteLine("What is the price?");
            double.TryParse(Console.ReadLine(), out double priceofCar);

            Console.WriteLine("How many miles ?");
            double.TryParse(Console.ReadLine(), out double milesofCar);

            CarLot.AddCar(new UsedCar(makeofCar, modelofCar, yearofCar, priceofCar, milesofCar));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Kyle Nedbal's Used Car Emporium!");
            Console.WriteLine();

            CarLot.cars.Add(new NewCar("Tesla", "Roadster", 2021, 130000.00));
            CarLot.cars.Add(new NewCar("Ford", "Mustang Mach-EV", 2021, 42500.00));
            CarLot.cars.Add(new NewCar("GMC", "Hummer EV", 2021, 105000.00));
            CarLot.cars.Add(new UsedCar("Lincoln", "Continental", 2018, 32000.00, 25000.00));
            CarLot.cars.Add(new UsedCar("Chevrolet", "Blazer RS", 2019, 29000.00, 36000.00));
            CarLot.cars.Add(new UsedCar("Jeep", "Grand Cherokee", 2017, 28000.00, 40000.00));

            bool userWantsToContinue = true;
            bool userChoice;

            do
            {
                do
                {
                    CarLot.ListCars(CarLot.cars);
                    Console.Write("Which car would you like?: ");
                    int validUserChoice;
                    userChoice = Int32.TryParse(Console.ReadLine(), out validUserChoice);
                    Console.WriteLine();

                    if (userChoice && validUserChoice > 0 && validUserChoice <= CarLot.cars.Count + 2)
                    {
                        if (validUserChoice > 0 && validUserChoice <= CarLot.cars.Count)
                        {
                            CarLot.cars[validUserChoice - 1].ToString();

                            Console.Write("Would you like to buy this car? (y/n): ");
                            string buyYN = Console.ReadLine().ToLower();
                            while (buyYN != "n" && buyYN != "y")
                            {
                                Console.Write("Please enter y or n to choose whether you'd like to buy this car: ");
                                buyYN = Console.ReadLine().ToLower();
                            }

                            if (buyYN == "y")
                            {
                                CarLot.RemoveCar(CarLot.cars[validUserChoice - 1]);
                                Console.WriteLine("Excellent! Our finance department will be in touch shortly");
                                Console.WriteLine();
                            }
                        }

                        else if (validUserChoice == CarLot.cars.Count + 1)
                        {
                            Console.Write("Enter the make: ");
                            string userMake = Console.ReadLine();
                            Console.Write("Enter the model: ");
                            string userModel = Console.ReadLine();
                            Console.Write("Enter the year: ");
                            int userYear = Int32.Parse(Console.ReadLine());
                            Console.Write("Enter the value of the car: ");
                            double userPrice = Double.Parse(Console.ReadLine());
                            Console.Write("Enter the mileage: ");
                            double userMileage = Double.Parse(Console.ReadLine());

                            CarLot.AddCar(new UsedCar(userMake, userModel, userYear, userPrice, userMileage));
                        }
                        else
                        {
                            userWantsToContinue = false;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid choice. Please enter the corresponding number to your choice showing on the list");
                    }
                } while (userChoice == false);
            } while (userWantsToContinue == true);

            Console.WriteLine("Have a great day!");
        }