Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- namespace Q4
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] lines = File.ReadAllLines(@"bus_174.csv");
- string[] header = lines[0].Split(",");
- Console.WriteLine("{0,-15}{1,-15}{2,-20}{3,-20}", header[0], header[1], header[2], header[3]);
- List<double> distance = new List<double>();
- List<string> codes = new List<string>();
- for (int i = 1; i < lines.Length; i++)
- {
- string[] data = lines[i].Split(",");
- Console.WriteLine("{0,-15}{1,-15}{2,-20}{3,-20}", data[0], data[1], data[2], data[3]);
- distance.Add(Convert.ToDouble(data[0]));
- codes.Add(data[1]);
- }
- string[] fare = File.ReadAllLines(@"distance-based-fare.csv");
- Console.Write("Enter boarding bus stop: ");
- string board = Convert.ToString(Console.ReadLine());
- Console.Write("Enter alighting bus stop: ");
- string alight = Convert.ToString(Console.ReadLine());
- double start = 0;
- double aligh = 0;
- decimal result = 0;
- for (int i = 0; i < codes.Count; i++)
- {
- if (board == codes[i])
- {
- start = distance[i];
- break;
- }
- else
- {
- continue;
- }
- }
- for (int j = 0; j < codes.Count; j++)
- {
- if (alight == codes[j])
- {
- aligh = distance[j];
- }
- else
- {
- continue;
- }
- }
- if (start != 0 && aligh != 0)
- {
- result = Convert.ToDecimal(aligh - start);
- result = Math.Round(result, 2);
- Console.WriteLine("Difference travelled : {0}km.", result);
- }
- else
- {
- Console.WriteLine("Incorrect bus stop number.");
- return;
- }
- List<double> upto = new List<double>();
- List<double> price = new List<double>();
- double final = 0;
- for (int n = 1; n < fare.Length; n++)
- {
- string[] tempo = fare[n].Split(",");
- upto.Add(Convert.ToDouble(tempo[0]));
- price.Add(Convert.ToDouble(tempo[1]));
- }
- for (int f = 0; f < price.Count; f++)
- {
- if (result <= Convert.ToDecimal(upto[f]))
- {
- final = price[f]/100;
- Console.WriteLine("Fare to pay : ${0}", final);
- break;
- }
- else
- continue;
- }
- decimal time = result * 4;
- Console.WriteLine("Estimated Duration: {0} mins", time);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement