Exemple #1
0
        static void Main(string[] args)
        {
            int    Weight;
            int    PassengerSeats;
            int    TankCapacity;
            double FuelFlow;
            int    MaxSpeed;
            int    HorsePower;
            string tmp;

            do
            {
                Console.WriteLine("Введите вес автомобиля : ");
                tmp = Console.ReadLine();
            } while (!int.TryParse(tmp, out Weight));

            do
            {
                Console.WriteLine("Введите кол-во пассажирских мест в автомобиле : ");
                tmp = Console.ReadLine();
            } while (!int.TryParse(tmp, out PassengerSeats));

            do
            {
                Console.WriteLine("Введите объем бака автомобиля : ");
                tmp = Console.ReadLine();
            } while (!int.TryParse(tmp, out TankCapacity));

            do
            {
                Console.WriteLine("Введите расход топлива на 100 километров : ");
                tmp = Console.ReadLine();
            } while (!double.TryParse(tmp, out FuelFlow));

            do
            {
                Console.WriteLine("Введите максимальную скорость автомобиля : ");
                tmp = Console.ReadLine();
            } while (!int.TryParse(tmp, out MaxSpeed));

            do
            {
                Console.WriteLine("Введите кол-во лошадиных сил автомобиля : ");
                tmp = Console.ReadLine();
            } while (!int.TryParse(tmp, out HorsePower));

            Car MyCar = new Car(Weight, PassengerSeats, TankCapacity, FuelFlow, MaxSpeed, HorsePower);

            int request = 1;

            while (request > 0)
            {
                Console.WriteLine("1 - Информация про автомобиль\n" +
                                  "2 - Переехать\n" +
                                  "3 - Заправить автомобиль\n" +
                                  "4 - Увеличить мощность двигателя\n" +
                                  "0 - Выход");
                do
                {
                    Console.Write("Ваш выбор : ");
                    tmp = Console.ReadLine();
                } while (!int.TryParse(tmp, out request) || (request < 0));

                double x;
                switch (request)
                {
                case 1:
                    MyCar.ShowInfo();
                    break;

                case 2:
                    tmp = Console.ReadLine();
                    double.TryParse(tmp, out x);
                    MyCar.Move(x);
                    break;

                case 3:
                    Console.Write("Введите кол-во топлива : ");
                    tmp = Console.ReadLine();
                    double.TryParse(tmp, out x);
                    MyCar.FillUpTank(x);
                    break;

                case 4:
                    MyCar.Upgrade();
                    break;

                default:
                    break;
                }
            }
        }