예제 #1
0
            static void Main(string[] args)
            {
                Car     newFord   = new Car("Ford", "Focus", 2008, 2000m);
                Car     newChevy  = new Car("Chevy", "Blazer", 2020, 42000m);
                Car     newJeep   = new Car("Jeep", "Compass", 2021, 48000m);
                UsedCar usedChevy = new UsedCar("Chevy", "Cruze", 2016, 5600m, 89500);
                UsedCar usedDodge = new UsedCar("Dodge", "Ram", 2008, 2400m, 150866);
                UsedCar usedFord  = new UsedCar("Ford", "F-150", 2016, 8450m, 65000);
                CarLot  cars      = new CarLot();

                cars.AddCar(newFord);
                cars.AddCar(newChevy);
                cars.AddCar(newJeep);
                cars.AddCar(usedChevy);
                cars.AddCar(usedDodge);
                cars.AddCar(usedFord);

                Console.WriteLine("welcome to Chelsea's Current Car Collection!");
                cars.ListCar();
            }
예제 #2
0
        static void Main(string[] args)
        {
            CarLot.AddCar(new Car("Chevy", "Blazer", 2021, 28800m));
            CarLot.AddCar(new Car("Kia", "Telluride", 2021, 32190m));
            CarLot.AddCar(new Car("Aston Martin", "Vantage", 2021, 139000m));
            CarLot.AddCar(new UsedCar("Alfa Romeo", "Stelvio Sport", 2018, 25990m, 41509));
            CarLot.AddCar(new UsedCar("Dodge", "Charger", 2019, 39646m, 15992));
            CarLot.AddCar(new UsedCar("GMC", "Yukon SLT", 2018, 45000m, 30864));

            bool done = false;

            while (!done)
            {
                Console.Clear();
                Console.WriteLine("Welcome to Grant Chirpus' Used Car Emporium!!\n");

                CarLot.ListCars();

                bool isValid = false;
                while (!isValid)
                {
                    Console.Write($"\nWhich car would you like? ");
                    bool isInt = Int32.TryParse(Console.ReadLine(), out int choice);
                    if (isInt && choice >= 1 && choice <= CarLot.carList.Count)
                    {
                        isValid = true;
                        Console.Clear();
                        Console.WriteLine($"You have selected the {CarLot.carList[choice - 1].Make} {CarLot.carList[choice - 1].Model} for ${CarLot.carList[choice - 1].Price}");

                        bool validAns = false;
                        while (!validAns)
                        {
                            Console.Write($"\nWould you like to buy the {CarLot.carList[choice - 1].Make} {CarLot.carList[choice - 1].Model}? (y/n): ");
                            string userAns = Console.ReadLine().ToLower();
                            if (userAns == "y" || userAns == "n")
                            {
                                validAns = true;
                                if (userAns == "y")
                                {
                                    Console.WriteLine($"Congratulations on your new {CarLot.carList[choice - 1].Make} {CarLot.carList[choice - 1].Model}!");
                                    CarLot.carList.RemoveAt(choice - 1);
                                }
                                else
                                {
                                    Console.WriteLine($"Are you sure??? Ok, no worries.");
                                }
                            }
                            else
                            {
                                Console.WriteLine("Sorry, that was not a valid option. Please try again");
                            }
                        }
                    }
                    else if (isInt && (choice == CarLot.carList.Count + 1 || choice == CarLot.carList.Count + 2))
                    {
                        isValid = true;
                        if (choice == CarLot.carList.Count + 1)
                        {
                            GetCarInfo();
                        }
                        else
                        {
                            done = true;
                            Console.Clear();
                            Console.WriteLine("Goodbye! Have a beautiful time!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Sorry, that was not a valid option. Please try again");
                    }
                }
            }
        }