Advertisement
Guest User

startup

a guest
Feb 4th, 2020
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace DefiningClasses
  5. {
  6. public class StartUp
  7. {
  8. public static void Main(string[] args)
  9. {
  10. int n = int.Parse(Console.ReadLine());
  11. List<Car> cars = new List<Car>();
  12. string command;
  13. for (int i = 0; i < n; i++)
  14. {
  15. //{model} {fuelAmount} {fuelConsumptionFor1km};
  16. string[] carArgs = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  17.  
  18. string model = carArgs[0];
  19. double fuelAmount = double.Parse(carArgs[1]);
  20. double fuelConsumptionFor1km = double.Parse(carArgs[2]);
  21.  
  22. Car car = new Car(model, fuelAmount, fuelConsumptionFor1km);
  23. cars.Add(car);
  24.  
  25. }
  26.  
  27. while (true)
  28. {
  29. command = Console.ReadLine();
  30. if (command == "End")
  31. {
  32. break;
  33. }
  34. string[] cmdArgs = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  35.  
  36. if (cmdArgs[0] == "End")
  37. {
  38. break;
  39. }
  40.  
  41. string carModel = cmdArgs[1];
  42. double amountOfKm = double.Parse(cmdArgs[2]);
  43.  
  44. cars.Where(c => c.model == carModel).ToList().ForEach(c => c.Drive(amountOfKm));
  45. }
  46.  
  47. foreach (Car car in cars)
  48. {
  49. //&quot;{model} {fuelAmount} {distanceTraveled}&quot;
  50. Console.WriteLine($"{car.model} {car.fuelAmount} {car.travelledDistance}");
  51.  
  52. }
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement