Guest User

Vehicles-1

a guest
Mar 2nd, 2018
391
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Text;
  3.  
  4. public class Program
  5. {
  6. static void Main()
  7. {
  8. Car car = (Car)Factory();
  9. Truck truck = (Truck)Factory();
  10. int cnt = int.Parse(Console.ReadLine());
  11.  
  12. StringBuilder str = new StringBuilder();
  13.  
  14. while (cnt > 0)
  15. {
  16. string command = Console.ReadLine().Trim();
  17. string[] data = command.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  18. string action = data[0] + data[1];
  19. action = action.ToLower();
  20. double argument = double.Parse(data[2]);
  21.  
  22. switch (action)
  23. {
  24. case "drivecar":
  25. str.AppendLine(car.Drive(argument));break;
  26. case "drivetruck":
  27. str.AppendLine(truck.Drive(argument));break;
  28. case "refuelcar":
  29. car.Refuel(argument);break;
  30. case "refueltruck":
  31. truck.Refuel(argument);break;
  32. }
  33. cnt--;
  34. }
  35. Console.WriteLine(str.ToString().Trim());
  36. Console.WriteLine(car);
  37. Console.WriteLine(truck);
  38. }
  39.  
  40. private static Vehicle Factory()
  41. {
  42. string[] part = Console.ReadLine().Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  43. double fuelQty = double.Parse(part[1]);
  44. double fuelConsumption = double.Parse(part[2]);
  45. switch (part[0])
  46. {
  47. case "Car":
  48. return new Car(fuelQty, fuelConsumption);
  49. case "Truck":
  50. return new Truck(fuelQty, fuelConsumption);
  51. default:
  52. return null;
  53. }
  54. }
  55. }
RAW Paste Data