Guest User

Untitled

a guest
Jun 24th, 2016
347
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3.  
  4. public class CarProblem
  5. {
  6. public static void Main()
  7. {
  8. int[] carInfo = Console.ReadLine().Split().Select(int.Parse).ToArray();
  9. int speed = carInfo[0];
  10. int fuel = carInfo[1];
  11. int fuelEconomy = carInfo[2];
  12. var car = new Car(speed, fuel, fuelEconomy);
  13. string input = Console.ReadLine();
  14.  
  15. while (input != "END")
  16. {
  17. string[] command = input.Split();
  18. if (command[0] == "Travel")
  19. {
  20. car.Travel(int.Parse(command[1]));
  21. }
  22. else if (command[0] == "Refuel")
  23. {
  24. car.Refuel(int.Parse(command[1]));
  25. }
  26. else if (command[0] == "Distance")
  27. {
  28. Console.WriteLine($"Total distance: {car.TotalDistance():f1} kilometers");
  29. }
  30. else if (command[0] == "Time")
  31. {
  32. Console.WriteLine($"Total time: {car.Hours()} hours and {car.Minutes()} minutes");
  33. }
  34. else if (command[0] == "Fuel")
  35. {
  36. Console.WriteLine($"Fuel left: {car.RemFuel():f1} liters");
  37. }
  38. input = Console.ReadLine();
  39. }
  40. }
  41. public class Car
  42. {
  43. public double speed;
  44. public double fuel;
  45. public double fuelEconomy;
  46. public double traveledDistance;
  47.  
  48. public Car(double speed, double fuel, double fuelEconomy)
  49. {
  50. this.speed = speed;
  51. this.fuel = fuel;
  52. this.fuelEconomy = fuelEconomy;
  53. }
  54. public void Travel(double distanceToTravel)
  55. {
  56. this.traveledDistance = distanceToTravel;
  57. }
  58. public void Refuel(double refuelAmount)
  59. {
  60. this.fuel += refuelAmount;
  61. }
  62. public double TotalDistance()
  63. {
  64. return this.traveledDistance;
  65. }
  66. public int Hours()
  67. {
  68. return (int)(this.traveledDistance / this.speed);
  69. }
  70. public double Minutes()
  71. {
  72. return (int)(this.traveledDistance % this.speed);
  73. }
  74. public double RemFuel()
  75. {
  76. return this.fuel - this.fuelEconomy * (this.traveledDistance / this.speed);
  77. }
  78. }
  79. }
RAW Paste Data