Advertisement
Guest User

Speed Racing

a guest
Jun 9th, 2020
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Problem_6._Speed_Racing
  6. {
  7.     public class StartUp
  8.     {
  9.         static void Main()
  10.         {
  11.             int numberOfcars = int.Parse(Console.ReadLine());
  12.             var cars = new List<Car>();
  13.  
  14.             for (int i = 0; i < numberOfcars; i++)
  15.             {
  16.                 var carInfo = Console.ReadLine().Split().ToArray();
  17.                 string model = carInfo[0];
  18.                 double fuelAmount = double.Parse(carInfo[1]);
  19.                 double fuelConsumptionPerKilometer = double.Parse(carInfo[2]);
  20.  
  21.                 Car car = new Car(model, fuelAmount, fuelConsumptionPerKilometer);
  22.                 cars.Add(car);
  23.                
  24.             }
  25.  
  26.             var input = Console.ReadLine();
  27.             while (input != "End")
  28.             {
  29.                 var driveInfo = input.Split().ToArray();
  30.                 string model = driveInfo[1];
  31.                 double amountOfKm = double.Parse(driveInfo[2]);
  32.  
  33.                 cars.Where(c => c.Model == model).ToList().ForEach(c => c.CanDriveTheDistance(amountOfKm));
  34.                 input = Console.ReadLine();
  35.             }
  36.             foreach (var car in cars)
  37.             {
  38.                 Console.WriteLine($"{car.Model} {car.FuelAmount:f2} {car.TravelledDistance}");
  39.             }
  40.  
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement