Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. namespace Q4
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string[] lines = File.ReadAllLines(@"bus_174.csv");
  13. string[] header = lines[0].Split(",");
  14. Console.WriteLine("{0,-15}{1,-15}{2,-20}{3,-20}", header[0], header[1], header[2], header[3]);
  15. List<double> distance = new List<double>();
  16. List<string> codes = new List<string>();
  17. for (int i = 1; i < lines.Length; i++)
  18. {
  19. string[] data = lines[i].Split(",");
  20. Console.WriteLine("{0,-15}{1,-15}{2,-20}{3,-20}", data[0], data[1], data[2], data[3]);
  21. distance.Add(Convert.ToDouble(data[0]));
  22. codes.Add(data[1]);
  23. }
  24. string[] fare = File.ReadAllLines(@"distance-based-fare.csv");
  25. Console.Write("Enter boarding bus stop: ");
  26. string board = Convert.ToString(Console.ReadLine());
  27. Console.Write("Enter alighting bus stop: ");
  28. string alight = Convert.ToString(Console.ReadLine());
  29. double start = 0;
  30. double aligh = 0;
  31. decimal result = 0;
  32. for (int i = 0; i < codes.Count; i++)
  33. {
  34. if (board == codes[i])
  35. {
  36. start = distance[i];
  37. break;
  38. }
  39. else
  40. {
  41. continue;
  42. }
  43. }
  44. for (int j = 0; j < codes.Count; j++)
  45. {
  46. if (alight == codes[j])
  47. {
  48. aligh = distance[j];
  49. }
  50. else
  51. {
  52. continue;
  53. }
  54. }
  55. if (start != 0 && aligh != 0)
  56. {
  57. result = Convert.ToDecimal(aligh - start);
  58. result = Math.Round(result, 2);
  59. Console.WriteLine("Difference travelled : {0}km.", result);
  60. }
  61. else
  62. {
  63. Console.WriteLine("Incorrect bus stop number.");
  64. return;
  65. }
  66. List<double> upto = new List<double>();
  67. List<double> price = new List<double>();
  68. double final = 0;
  69. for (int n = 1; n < fare.Length; n++)
  70. {
  71. string[] tempo = fare[n].Split(",");
  72. upto.Add(Convert.ToDouble(tempo[0]));
  73. price.Add(Convert.ToDouble(tempo[1]));
  74. }
  75. for (int f = 0; f < price.Count; f++)
  76. {
  77. if (result <= Convert.ToDecimal(upto[f]))
  78. {
  79. final = price[f]/100;
  80.  
  81. Console.WriteLine("Fare to pay : ${0}", final);
  82. break;
  83. }
  84. else
  85. continue;
  86. }
  87. decimal time = result * 4;
  88. Console.WriteLine("Estimated Duration: {0} mins", time);
  89.  
  90.  
  91.  
  92.  
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement