Exemple #1
0
        static void Main(string[] args)
        {
            CarLot.CarsInLot.Add(new UsedCar("Ford", "Focus", 2014, 278900, 8764));
            CarLot.CarsInLot.Add(new UsedCar("Chevy", "Camaro", 2015, 78970, 64546));
            CarLot.CarsInLot.Add(new UsedCar("Honda", "Civic", 2016, 53450, 9875656));
            CarLot.CarsInLot.Add(new Car("Toyota", "Supra", 2017, 26765));
            CarLot.CarsInLot.Add(new Car("Chrysler", "300", 2018, 7700));
            CarLot.CarsInLot.Add(new Car("Dodge", "Ram", 2019, 500));
            bool continueFlag = true;

            Console.WriteLine("Welcome to the Car Lot!\n");
            //Console.WriteLine(CarLot.CarsInLot.Count);

            while (continueFlag)
            {
                CarLot.ListCars();
                Console.WriteLine($"{CarLot.CarsInLot.Count + 1}. Add a car");
                Console.WriteLine($"{CarLot.CarsInLot.Count + 2}. Quit");
                Console.WriteLine();
                Console.Write("Which car would you like?: ");
                int userInput = IntValidation(Console.ReadLine());
                if (userInput == CarLot.CarsInLot.Count + 2)
                {
                    Console.WriteLine("OK BYEEEE!!!!!");
                    continueFlag = false;
                    break;
                }
                if (userInput == CarLot.CarsInLot.Count + 1)
                {
                    Console.WriteLine();
                    Console.Write("Is this a new or used car?: ");
                    string usedOrNew = Console.ReadLine();
                    while (usedOrNew.ToLower() != "new" && usedOrNew.ToLower() != "used")
                    {
                        Console.Write("Please enter \"new\" or \"used\": ");
                        usedOrNew = Console.ReadLine();
                    }
                    Console.Write("Please enter a Make: ");
                    string make = Console.ReadLine();
                    Console.Write("Please enter a Model: ");
                    string model = Console.ReadLine();
                    Console.Write("Please enter a Year: ");
                    string year = Console.ReadLine();
                    int    validYear;
                    while (!int.TryParse(year, out validYear))
                    {
                        Console.Write($"Please a valid year: ");
                        year = Console.ReadLine();
                    }
                    Console.Write("Please enter a valid price: ");
                    string price = Console.ReadLine();
                    double validPrice;
                    while (!double.TryParse(price, out validPrice))
                    {
                        Console.Write($"Please a valid price: ");
                        price = Console.ReadLine();
                    }
                    if (usedOrNew == "new")
                    {
                        CarLot.CarsInLot.Add(new Car(make, model, validYear, validPrice));
                    }
                    else if (usedOrNew == "used")
                    {
                        Console.Write("Please enter the mileage: ");
                        string mileage = Console.ReadLine();
                        int    validMileage;
                        while (!int.TryParse(mileage, out validMileage))
                        {
                            Console.Write($"Please a valid mileage: ");
                            mileage = Console.ReadLine();
                        }
                        CarLot.CarsInLot.Add(new UsedCar(make, model, validYear, validPrice, validMileage));
                    }
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine($"\n{CarLot.CarsInLot[userInput - 1]}");
                    Console.Write("Would you like to purchase this car? (y/n): ");
                    string userPurchase = YesOrNo(Console.ReadLine());  //We gonna purchase?
                    if (userPurchase == "y")
                    {
                        Console.WriteLine("\nExcellent! Our Financial department will be in touch shortly!\n ");
                        CarLot.RemoveCar(userInput - 1);
                    }
                    else
                    {
                        Console.WriteLine("Well... fine....\n");
                    }
                }
            }
        }
Exemple #2
0
        static void RunProgram()
        {
            CarLot emporium = new CarLot("Grant Chirpus’ Used Car Emporium");

            Console.WriteLine(emporium.GreetingClients());
            emporium.ListAllCars();
            bool runProgram = true;
            int  userInput  = 0;

            while (runProgram)
            {
                Console.WriteLine("Enter your choice");
                Car  newCar  = new Car();
                Used usedCar = new Used();
                int  count1  = emporium.Inventory.Count;
                //int input = int.Parse(Console.ReadLine());
                //bool userChoice = Validator.ValidatoryInput(input, count1);
                try
                {
                    //    userInput = int.Parse(Console.ReadLine());
                    //    if(userInput <= 0 || userInput > emporium.Inventory.Count+ 2 )
                    //    {
                    //        Console.WriteLine("Not less than 0 and more than the list");
                    //        continue;
                    //    }

                    //}
                    int  input      = int.Parse(Console.ReadLine());
                    bool userChoice = Validator.ValidatoryInput(input, count1);

                    //catch(Exception)
                    //{
                    //    Console.WriteLine("not a number");
                    //    continue;
                    //}
                    if (userChoice)
                    {
                        if (input == emporium.Inventory.Count + 1)
                        {
                            Console.WriteLine("Do you want to add a new car or used car?");
                            string choice = Console.ReadLine().Trim().ToLower();
                            if (choice == "new")
                            {
                                Console.WriteLine("Make of the car:");
                                newCar.Make = Console.ReadLine();
                                Console.WriteLine("Model of the car:");
                                newCar.Model = Console.ReadLine();
                                Console.WriteLine("Year of the car:");
                                newCar.Year = int.Parse(Console.ReadLine());
                                Console.WriteLine("Price of the car:");
                                newCar.Price = decimal.Parse(Console.ReadLine());
                                Console.WriteLine("Your car has been added");
                                emporium.AddNewCars(newCar); // This will store it in the data collection
                                emporium.ListAllCars();
                            }

                            else if (choice == "used")
                            {
                                Console.WriteLine("Make of the car:");
                                usedCar.Make = Console.ReadLine();
                                Console.WriteLine("Model of the car:");
                                usedCar.Model = Console.ReadLine();
                                Console.WriteLine("Year of the car:");
                                usedCar.Year = int.Parse(Console.ReadLine());
                                Console.WriteLine("Price of the car:");
                                usedCar.Price = decimal.Parse(Console.ReadLine());
                                Console.WriteLine("Milleage of the car:");
                                usedCar.Mileage = double.Parse(Console.ReadLine());

                                emporium.AddNewCars(usedCar); // This will store it in the data collection
                                emporium.ListAllCars();
                            }
                            else
                            {
                                Console.WriteLine("Your choice is invalid");
                            }
                        }



                        else if (input == emporium.Inventory.Count + 2)
                        {
                            Console.WriteLine("Good bye");
                            Environment.Exit(0);
                        }
                        else
                        {
                            emporium.ViewCar(input);
                            Console.WriteLine("Do you want to buy this car?y/n");
                            string inputChoice = Console.ReadLine();
                            if (inputChoice == "y")
                            {
                                Console.WriteLine("Excellent!  Our finance department will be in touch shortly.");
                                emporium.RemoveCar(input);
                                emporium.ListAllCars();
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("not a number");
                    continue;
                }

                while (true)
                {
                    Console.WriteLine("Do you want to continue?y/n");
                    string choice = Console.ReadLine().ToLower().Trim();
                    if (choice == "y")
                    {
                        Console.Clear();
                        emporium.ListAllCars();
                        break;
                    }
                    else if (choice == "n")
                    {
                        runProgram = false;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Wrong input.Please type y/n");
                    }
                }
            }
        }