Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace DefiningClasses
- {
- public class StartUp
- {
- public static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<Car> cars = new List<Car>();
- string command;
- for (int i = 0; i < n; i++)
- {
- //{model} {fuelAmount} {fuelConsumptionFor1km};
- string[] carArgs = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
- string model = carArgs[0];
- double fuelAmount = double.Parse(carArgs[1]);
- double fuelConsumptionFor1km = double.Parse(carArgs[2]);
- Car car = new Car(model, fuelAmount, fuelConsumptionFor1km);
- cars.Add(car);
- }
- while (true)
- {
- command = Console.ReadLine();
- if (command == "End")
- {
- break;
- }
- string[] cmdArgs = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
- if (cmdArgs[0] == "End")
- {
- break;
- }
- string carModel = cmdArgs[1];
- double amountOfKm = double.Parse(cmdArgs[2]);
- cars.Where(c => c.model == carModel).ToList().ForEach(c => c.Drive(amountOfKm));
- }
- foreach (Car car in cars)
- {
- //"{model} {fuelAmount} {distanceTraveled}"
- Console.WriteLine($"{car.model} {car.fuelAmount} {car.travelledDistance}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement