コード例 #1
0
        public static void Main(string[] args)
        {
            var garage1 = new Garage();

            garage1.AddCar("Audi RS6", "Red", 305, 2020);
            while (true)
            {
                Console.Clear();
                Console.WriteLine("Добро пожаловать в ваш гараж, что хотите сделать?");
                Console.WriteLine(
                    "1)Вывести список автомобилей\n" +
                    "2)Добавить автомобиль\n" +
                    "3)Убрать автомобиль\n" +
                    "4)Прокатиться на автомобиле!\n" +
                    "5)Выход\n");
                int input;

                while (!int.TryParse(Console.ReadLine(), out input) || input < 0 || input > 5)
                {
                    Console.Write("Некорректный ввод. Попробуйте снова: ");
                }
                switch (input)
                {
                //Показать автомобили
                case 1:
                    Console.Clear();
                    garage1.ShowCars();
                    Console.ReadKey();
                    break;

                //Добавить автомобиль
                case 2:
                    Console.Clear();
                    string carModel, color;
                    float  speed;
                    int    yearOfIssue;
                    Console.Write("Введите марку автомобиля: ");
                    while (true)
                    {
                        carModel = Console.ReadLine();
                        if (string.IsNullOrEmpty(carModel))
                        {
                            Console.Write("Некорректный ввод. Попробуйте снова: ");
                        }
                        else
                        {
                            break;
                        }
                    }

                    Console.Write("Введите цвет машины: ");
                    while (true)
                    {
                        color = Console.ReadLine();
                        if (string.IsNullOrEmpty(color))
                        {
                            Console.Write("Некорректный ввод. Попробуйте снова: ");
                        }
                        else
                        {
                            break;
                        }
                    }

                    Console.Write("Введите скорость машины: ");
                    while (!float.TryParse(Console.ReadLine(), out speed) || speed <= 0)
                    {
                        Console.Write(
                            "Некорректный ввод. Скорость не может быть равна или меньше 0. Попробуйте снова: ");
                    }

                    Console.Write("Введите год выпуска машины: ");
                    while (!int.TryParse(Console.ReadLine(), out yearOfIssue) || yearOfIssue <= 0)
                    {
                        Console.Write(
                            "Некорректный ввод. Год выпуска не может быть равен или меньшим 0. Попробуйте снова: ");
                    }

                    garage1.AddCar(carModel, color, speed, yearOfIssue);
                    break;

                //Удалить автомобиль
                case 3:
                    Console.Clear();

                    if (garage1.CountCars() > 1)
                    {
                        int lowInput;
                        Console.WriteLine("Какой из автомобилей хотите убрать из гаража?");
                        garage1.ShowCars();

                        while (!int.TryParse(Console.ReadLine(), out lowInput) || lowInput <= 0 ||
                               lowInput > garage1.CountCars())
                        {
                            Console.Write("Некорректный ввод. Попробуйте снова: ");
                        }
                        garage1.DeleteCar(lowInput);
                    }
                    else
                    {
                        garage1.DeleteCar(0);
                    }

                    break;

                //Выехать на автомобиле
                case 4:
                    if (garage1.CountCars() > 1)
                    {
                        int lowInput;
                        Console.WriteLine("На чём прокатимся?");
                        garage1.ShowCars();

                        while (!int.TryParse(Console.ReadLine(), out lowInput) || lowInput <= 0 ||
                               lowInput > garage1.CountCars())
                        {
                            Console.Write("Некорректный ввод. Попробуйте снова: ");
                        }
                        garage1.RideCar(lowInput);
                    }
                    else
                    {
                        garage1.RideCar(0);
                    }

                    break;

                case 5:
                    break;
                }

                if (input == 5)
                {
                    break;
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Garage myGarage = new Garage();

            Console.WriteLine("Виберіть машину:");
            int choice;

            do
            {
                Console.WriteLine();
                if (myGarage.myCars.Count == 0)
                {
                    Console.WriteLine("Введіть 0, аби залишити гараж");
                    Console.WriteLine("Введіть 1, аби поставити нову машину в гараж");
                }
                else
                {
                    Console.WriteLine("Введіть 0, аби залишити гараж");
                    Console.WriteLine("Введіть 1, аби поставити нову машину в гараж");
                    Console.WriteLine("Введіть 2, аби побачити усі машини");
                    Console.WriteLine("Введіть 3, аби прибрати машину з гаражу");
                    Console.WriteLine("Введіть 4, аби вибрати машину за критеріями");
                }
                Console.Write("Введіть запит:");
                while (!int.TryParse(Console.ReadLine(), out choice))
                {
                    Console.WriteLine("Введіть корректний запит: ");
                }
                switch (choice)
                {
                case 0:
                    Console.WriteLine("Гараз зачинено.");
                    return;

                case 1:
                    Console.WriteLine("Машину поставлено");
                    myGarage.Addition();
                    Console.WriteLine(myGarage.myCars.Count);
                    break;

                case 2:
                    myGarage.AllCars();
                    break;

                case 3:
                    myGarage.DeleteCar();
                    break;

                case 4:
                    Console.WriteLine("За якою характеристикою шукаємо");
                    char characteristic;
                    Console.WriteLine("n - Ім'я");
                    Console.WriteLine("c - Колір");
                    Console.WriteLine("s - Швидкість");
                    Console.WriteLine("y - Рік випуску");
                    characteristic = Convert.ToChar(Console.ReadLine());
                    myGarage.CharacteristicSearch(characteristic);
                    break;

                default:
                    Console.WriteLine("Помилка! Введіть щось з наведеного");
                    break;
                }
            } while (choice != 0);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            while (true)
            {
                int n = 0;
                Console.Write("Enter the option(Add - 1, Remove - 2, Find - 3, Show the garage - 4:");
                int    tempYear = 0;
                double tempSpeed = 0;
                string tempName, tempColor;
                if (int.TryParse(Console.ReadLine(), out n))
                {
                    switch (n)
                    {
                    case 1:
                    {
                        Console.WriteLine("Enter the options(for adding):");
                        Console.Write("\tName:");
                        tempName = Console.ReadLine();
                        Console.Write("\tSpeed:");
                        double.TryParse(Console.ReadLine(), out tempSpeed);
                        Console.Write("\tColor:");
                        tempColor = Console.ReadLine();
                        Console.Write("\tYear:");
                        int.TryParse(Console.ReadLine(), out tempYear);
                        Car car = new Car(tempYear, tempName, tempColor, tempSpeed);
                        Garage.AddCar(car);
                        Console.WriteLine("Car was added");
                    }
                    break;

                    case 2:
                    {
                        Console.WriteLine("Enter the options(for removing):");
                        Console.Write("\tName:");
                        tempName = Console.ReadLine();
                        Console.Write("\tSpeed:");
                        double.TryParse(Console.ReadLine(), out tempSpeed);
                        Console.Write("\tColor:");
                        tempColor = Console.ReadLine();
                        Console.Write("\tYear:");
                        int.TryParse(Console.ReadLine(), out tempYear);
                        Car car = new Car(tempYear, tempName, tempColor, tempSpeed);
                        Garage.RemoveCar(car);
                        Console.WriteLine("Car was removed if had been found");
                    }
                    break;

                    case 3:
                    {
                        Console.WriteLine("Enter the options(for finding):");
                        Console.Write("\tName:");
                        tempName = Console.ReadLine();
                        Console.Write("\tSpeed:");
                        double.TryParse(Console.ReadLine(), out tempSpeed);
                        Console.Write("\tColor:");
                        tempColor = Console.ReadLine();
                        Console.Write("\tYear:");
                        int.TryParse(Console.ReadLine(), out tempYear);
                        Car car = new Car(tempYear, tempName, tempColor, tempSpeed);
                        Garage.ShowFindCars(Garage.SequenceCar(car));
                    }
                    break;

                    case 4:
                    {
                        Garage.ShowGarage();
                    }
                    break;

                    default: Console.WriteLine("Incorrect value"); break;
                    }
                }
                else
                {
                    continue;
                }
            }
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Garage garage = new Garage();
            int    count;
            bool   a;

            List <Car> carList = new List <Car>()
            {
                new Car()
                {
                    name = "BMW M2", color = "Red", speed = 250, year = 2019
                },
                new Car()
                {
                    name = "BMW M5", color = "Black", speed = 300, year = 2019
                },
                new Car()
                {
                    name = "BMW X6", color = "Black", speed = 320, year = 2019
                },
                new Car()
                {
                    name = "Audi A4", color = "Red", speed = 220, year = 2016
                },
                new Car()
                {
                    name = "Audi A7", color = "Silver", speed = 250, year = 2018
                },
                new Car()
                {
                    name = "Audi Q7", color = "Black", speed = 290, year = 2018
                },
                new Car()
                {
                    name = "Audi S4", color = "Red", speed = 200, year = 2013
                },
                new Car()
                {
                    name = "Nissan GT-R R35", color = "White", speed = 320, year = 2017
                }
            };


            do
            {
                Console.WriteLine("1) Show all the cars in the garage");
                Console.WriteLine("2) Add car to the garage");
                Console.WriteLine("3) Delete car from the garage");
                Console.WriteLine("4) Choose your car from the garage");
                Console.WriteLine("0) Exit");
                do
                {
                    Console.Write("Enter your choise: ");
                    a = int.TryParse(Console.ReadLine(), out count);
                    if (!a || count >= 5)
                    {
                        Console.WriteLine("Wrong number!");
                    }
                } while (!a || count >= 5);
                switch (count)
                {
                case 1:
                    if (garage.garageList == null)
                    {
                        Console.WriteLine("Garage is empty");
                    }
                    else
                    {
                        garage.showAllCars();
                    }

                    break;

                case 2:
                    for (int i = 0; i < carList.Count; i++)
                    {
                        Console.WriteLine($"{carList[i].name} - {carList[i].color} - {carList[i].speed} - {carList[i].year}; Index = {i + 1}");
                    }
                    do
                    {
                        Console.Write("Enter the index to buy the car: ");
                        a = int.TryParse(Console.ReadLine(), out count);
                        if (!a || count > carList.Count)
                        {
                            Console.WriteLine("Wrong index!");
                        }
                    } while (!a || count > carList.Count);
                    garage.addCar(count, carList);

                    break;

                case 3:
                    if (garage.garageList == null)
                    {
                        Console.WriteLine("Garage is empty");
                    }
                    else
                    {
                        for (int i = 0; i < garage.garageList.Count; i++)
                        {
                            Console.WriteLine($"{garage.garageList[i].name} - {garage.garageList[i].color} - {garage.garageList[i].speed} - {garage.garageList[i].year}; Index = {i + 1}");
                        }
                        do
                        {
                            Console.Write("Enter the index to remove the car: ");
                            a = int.TryParse(Console.ReadLine(), out count);
                            if (!a || count > garage.garageList.Count)
                            {
                                Console.WriteLine("Wrong index!");
                            }
                        } while (!a || count > garage.garageList.Count);
                        garage.removeCar(count);
                    }

                    break;

                case 4:
                    string carName = null, carColor = null;
                    int    carSpeed = 0, carYear = 0;
                    if (garage.garageList == null)
                    {
                        Console.WriteLine("Garage is empty");
                    }
                    else
                    {
                        for (int i = 0; i < garage.garageList.Count; i++)
                        {
                            Console.WriteLine($"{garage.garageList[i].name} - {garage.garageList[i].color} - {garage.garageList[i].speed} - {garage.garageList[i].year}; Index = {i + 1}");
                        }
                        do
                        {
                            Console.WriteLine($"1) Car name {(carName == null ? "#" : carName)}");
                            Console.WriteLine($"2) Car color {(carColor == null ? "#" : carColor)}");
                            Console.WriteLine($"3) Car speed {(carSpeed == 0 ? 0 : carSpeed)}");
                            Console.WriteLine($"4) Car year {(carYear == 0 ? 0 : carYear)}");
                            Console.WriteLine("0) Exit");
                            Console.WriteLine("0 or # - any value");
                            do
                            {
                                Console.Write("Enter your choise: ");
                                a = int.TryParse(Console.ReadLine(), out count);
                                if (!a || count >= 5)
                                {
                                    Console.WriteLine("Wrong number!");
                                }
                            } while (!a || count >= 5);
                            Console.WriteLine();
                            switch (count)
                            {
                            case 1:
                                for (int i = 0; i < garage.garageList.Count; i++)
                                {
                                    Console.WriteLine($"Year - {garage.garageList[i].name}");
                                }
                                carName = Console.ReadLine();

                                break;

                            case 2:
                                for (int i = 0; i < garage.garageList.Count; i++)
                                {
                                    Console.WriteLine($"Year - {garage.garageList[i].color}");
                                }
                                carColor = Console.ReadLine();

                                break;

                            case 3:
                                for (int i = 0; i < garage.garageList.Count; i++)
                                {
                                    Console.WriteLine($"Year - {garage.garageList[i].speed}");
                                }
                                do
                                {
                                    Console.Write("Enter your choise: ");
                                    a = int.TryParse(Console.ReadLine(), out carSpeed);
                                    if (!a)
                                    {
                                        Console.WriteLine("Wrong number!");
                                    }
                                } while (!a);

                                break;

                            case 4:
                                for (int i = 0; i < garage.garageList.Count; i++)
                                {
                                    Console.WriteLine($"Year - {garage.garageList[i].year}");
                                }
                                do
                                {
                                    Console.Write("Enter your choise: ");
                                    a = int.TryParse(Console.ReadLine(), out carYear);
                                    if (!a)
                                    {
                                        Console.WriteLine("Wrong number!");
                                    }
                                } while (!a);
                                break;

                            default:
                                break;
                            }
                            Console.WriteLine();
                            garage.chooseCar(carName, carColor, carSpeed, carYear);
                            Console.WriteLine();
                        } while (count != 0);
                    }

                    break;

                default:
                    break;
                }
            } while (count != 0);
        }