Advertisement
joro_thexfiles

Problem_6_Speed_Racing

Feb 5th, 2020
1,709
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace DefiningClasses
  6. {
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.  
  13.             List<Car> cars = new List<Car>();
  14.  
  15.             for (int i = 0; i <n; i++)
  16.             {
  17.                 string[] data = Console.ReadLine()
  18.                     .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  19.                     .ToArray();
  20.  
  21.                 string model = data[0];
  22.                 double fuelAmount = double.Parse(data[1]);
  23.                 double fuelConsumption = double.Parse(data[2]);
  24.  
  25.                 Car currentCar = new Car(model, fuelAmount, fuelConsumption);
  26.  
  27.                 cars.Add(currentCar);
  28.             }
  29.  
  30.             while (true)
  31.             {
  32.                 string input = Console.ReadLine();
  33.  
  34.                 if (input == "End")
  35.                 {
  36.                     break;
  37.                 }
  38.                 else
  39.                 {
  40.                     string[] data = input
  41.                         .Split(' ')
  42.                         .ToArray();
  43.  
  44.                     string model = data[1];
  45.                     double amountKm = double.Parse(data[2]);
  46.  
  47.                     Car carForDriving = cars
  48.                         .Where(x => x.Model == model)
  49.                         .ToList()
  50.                         .First();
  51.  
  52.                     carForDriving.CanIReachTheDistance(model, amountKm);    
  53.                 }
  54.             }
  55.  
  56.             foreach (var item in cars)
  57.             {
  58.                 Console.WriteLine($"{ item.Model} { item.FuelAmount:F2} {item.TravelledDistance}");
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement