コード例 #1
0
ファイル: Program.cs プロジェクト: VenziVi/SoftUni
        static void Main(string[] args)
        {
            List <Car>     listCars     = new List <Car>();
            List <Tires[]> tiresList    = new List <Tires[]>();
            List <Engine>  engineList   = new List <Engine>();
            List <double>  pressureSums = new List <double>();

            string tireInput = Console.ReadLine();

            while (tireInput != "No more tires")
            {
                //2 2.6 3 1.6 2 3.6 3 1.6
                string[] tyresInfo       = tireInput.Split();
                double   tirePressureSum = 0;
                Tires[]  tires           = new Tires[4]
                {
                    new Tires(int.Parse(tyresInfo[0]), double.Parse(tyresInfo[1])),
                    new Tires(int.Parse(tyresInfo[2]), double.Parse(tyresInfo[3])),
                    new Tires(int.Parse(tyresInfo[4]), double.Parse(tyresInfo[5])),
                    new Tires(int.Parse(tyresInfo[6]), double.Parse(tyresInfo[7])),
                };

                tirePressureSum = double.Parse(tyresInfo[1]) + double.Parse(tyresInfo[3]) + double.Parse(tyresInfo[5]) + double.Parse(tyresInfo[7]);
                pressureSums.Add(tirePressureSum);
                tiresList.Add(tires);

                tireInput = Console.ReadLine();
            }

            string engineInput = Console.ReadLine();

            while (engineInput != "Engines done")
            {
                string[] engineInfo = engineInput.Split();

                Engine engine = new Engine(int.Parse(engineInfo[0]), double.Parse(engineInfo[1]));
                engineList.Add(engine);

                engineInput = Console.ReadLine();
            }

            string carInput = Console.ReadLine();

            while (carInput != "Show special")
            {
                //{ make} { model} { year} { fuelquantity} { fuelconsumption} { engineindex} { tiresindex}
                string[] carInfo         = carInput.Split();
                string   make            = carInfo[0];
                string   model           = carInfo[1];
                int      year            = int.Parse(carInfo[2]);
                double   fuelQuantity    = double.Parse(carInfo[3]);
                double   fuelConsumption = double.Parse(carInfo[4]);
                int      engineIndex     = int.Parse(carInfo[5]);
                int      tiresIndex      = int.Parse(carInfo[6]);

                Engine  engine        = engineList[engineIndex];
                Tires[] tires         = tiresList[tiresIndex];
                double  totalPressure = pressureSums[tiresIndex];

                Car car = new Car(make, model, year, fuelQuantity, fuelConsumption, engine, tires, totalPressure);

                listCars.Add(car);

                carInput = Console.ReadLine();
            }

            foreach (Car car in listCars)
            {
                if (car.Year >= 2017 && car.Engine.HorsePower >= 330 && car.TotalPressure >= 9 && car.TotalPressure <= 10)
                {
                    car.Drive(20);

                    Console.WriteLine($"Make: {car.Make}\nModel: {car.Model}\nYear: {car.Year}\n" +
                                      $"HorsePowers: {car.Engine.HorsePower}\nFuelQuantity: {car.FuelQuantity}");
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            List <List <double> > listTiresYears     = new List <List <double> >();
            List <List <double> > listTiresPressures = new List <List <double> >();
            List <int>            listHorsePowers    = new List <int>();
            List <double>         listCubicCapacity  = new List <double>();

            List <Car> listCars = new List <Car>();


            string input = Console.ReadLine();

            Tires  tires  = new Tires();
            Engine engine = new Engine();

            while (input != "No more tires")
            {
                string[] splitted = input.Split();

                List <double> listYears     = tires.GetYearInfo(splitted);
                List <double> listPressures = tires.GetPressureInfo(splitted);

                listTiresYears.Add(listYears);
                listTiresPressures.Add(listPressures);

                input = Console.ReadLine();
            }

            string secondInput = Console.ReadLine();

            while (secondInput != "Engines done")
            {
                string[] splitted = secondInput.Split();

                listHorsePowers.Add(engine.GetHorsePower(splitted));
                listCubicCapacity.Add(engine.GetCubicCapacity(splitted));

                secondInput = Console.ReadLine();
            }

            string thirdInput = Console.ReadLine();

            while (thirdInput != "Show special")
            {
                string[] splitted        = thirdInput.Split();
                string   make            = splitted[0];
                string   model           = splitted[1];
                int      year            = int.Parse(splitted[2]);
                double   fuelQuantity    = double.Parse(splitted[3]);
                double   fuelConsumption = double.Parse(splitted[4]);
                int      engineIndex     = int.Parse(splitted[5]);
                int      tiresIndex      = int.Parse(splitted[6]);

                int    horsePower = listHorsePowers[engineIndex];
                double pressure   = tires.GetSumPressure(listTiresPressures, tiresIndex);

                Car car = new Car(make, model, year, horsePower, fuelQuantity, fuelConsumption,
                                  engineIndex, tiresIndex, pressure);

                listCars.Add(car);


                thirdInput = Console.ReadLine();
            }

            foreach (var car in listCars)
            {
                if (car.Year >= 2017 && car.HorsePower > 330 &&
                    car.TotalPressure > 9 && car.TotalPressure < 10)
                {
                    car.FuelQuantity = car.Drive20Kilometers(car.FuelQuantity, car.FuelConsumption);

                    Console.WriteLine($"Make: {car.Make}");

                    Console.WriteLine($"Model: {car.Model}");

                    Console.WriteLine($"Year: {car.Year}");

                    Console.WriteLine($"HorsePowers: {car.HorsePower}");

                    Console.WriteLine($"FuelQuantity: {car.FuelQuantity}");
                }
            }
        }