Beispiel #1
0
        public static void Main()
        {
            int    countCars = int.Parse(Console.ReadLine());
            Garage garage    = new Garage();

            for (int i = 1; i <= countCars; i++)
            {
                string[] carInfo = Console.ReadLine()
                                   .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string carModel      = carInfo[0];
                double carFuelAmount = double.Parse(carInfo[1]);
                double carFuelConsumptionPerKilometer = double.Parse(carInfo[2]);

                Car currentCar = new Car(carModel, carFuelAmount, carFuelConsumptionPerKilometer);
                garage.Add(currentCar);
            }

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "End")
            {
                string[] splittedInput = input
                                         .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string model    = splittedInput[1];
                double distance = double.Parse(splittedInput[2]);

                Car currentCar = garage.FindCar(model);

                if (currentCar.CanMove(distance))
                {
                    currentCar.Move(distance);
                }
                else
                {
                    Console.WriteLine("Insufficient fuel for the drive");
                }
            }

            garage.Print();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

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

            for (int i = 0; i < n; i++)
            {
                string[] options = Console.ReadLine().Split();

                cars.Add(new Car(options[0], double.Parse(options[1]), double.Parse(options[2])));
            }

            string input = string.Empty;

            while ((input = Console.ReadLine()) != "End")
            {
                string[] options = input.Split();

                string model      = options[1];
                double amountOfKm = double.Parse(options[2]);

                Car car = cars.Find(x => x.Model == model);

                if (car.CanMove(amountOfKm))
                {
                    car.Drive(amountOfKm);
                }
                else
                {
                    Console.WriteLine($"Insufficient fuel for the drive");
                }
            }

            foreach (var car in cars)
            {
                Console.WriteLine($"{car.Model} {car.FuelAmount:f2} {car.TravelledDistance:f0}");
            }
        }