static void Main(string[] args) { logger.LogInfo("Log initialized"); var lines = File.ReadAllLines(csvPath); if (lines.Length <= 1) { logger.LogError("No or not enough lines"); } logger.LogInfo($"Lines: {lines[0]}"); var parser = new TacoParser(); double distance = 0.00; var locations = lines.Select(parser.Parse); TacoBell local1 = new TacoBell(); TacoBell local2 = new TacoBell(); //GeoCoordinate geoCoordinate = new GeoCoordinate(); GeoPosition <GeoCoordinate> geoPosition = new GeoPosition <GeoCoordinate>(); foreach (var location in locations) { GeoCoordinate geoCoord = new GeoCoordinate(location.Location.Latitude, location.Location.Longitude); foreach (var Blocation in locations) { GeoCoordinate geoCoord2 = new GeoCoordinate(Blocation.Location.Latitude, Blocation.Location.Longitude); if (geoCoord.GetDistanceTo(geoCoord2) == 0) { logger.LogInfo("Same Location"); } else if (geoCoord.GetDistanceTo(geoCoord2) > distance) { distance = geoCoord.GetDistanceTo(geoCoord2); Point point1 = new Point(location.Location.Latitude, location.Location.Longitude); local1.SetLocation(point1); local1.SetName(location.Name); Point point2 = new Point(Blocation.Location.Latitude, Blocation.Location.Longitude); local2.SetLocation(point2); local2.SetName(Blocation.Name); } else { } } //Console.WriteLine(location.Name); //Console.ReadLine(); } logger.LogInfo("Greatest distance"); Console.WriteLine(distance); logger.LogInfo("Location #1 Name"); Console.WriteLine(local1.GetName()); logger.LogInfo("Location #2 Name"); Console.WriteLine(local2.GetName()); Console.ReadLine(); Console.ReadLine(); // TODO: Find the two Taco Bells in Alabama that are the furthest from one another. // HINT: You'll need two nested forloops // DON'T FORGET TO LOG YOUR STEPS // Grab the path from the name of your file // use File.ReadAllLines(path) to grab all the lines from your csv file // Log and error if you get 0 lines and a warning if you get 1 line // Create a new instance of your TacoParser class // Grab an IEnumerable of locations using the Select command: var locations = lines.Select(parser.Parse); // Now, here's the new code // Create two `ITrackable` variables with initial values of `null`. These will be used to store your two taco bells that are the furthest from each other. // Create a `double` variable to store the distance // Include the Geolocation toolbox, so you can compare locations: `using GeoCoordinatePortable;` // Do a loop for your locations to grab each location as the origin (perhaps: `locA`) // Create a new corA Coordinate with your locA's lat and long // Now, do another loop on the locations with the scope of your first loop, so you can grab the "destination" location (perhaps: `locB`) // Create a new Coordinate with your locB's lat and long // Now, compare the two using `.GetDistanceTo()`, which returns a double // If the distance is greater than the currently saved distance, update the distance and the two `ITrackable` variables you set above // Once you've looped through everything, you've found the two Taco Bells furthest away from each other. }
public ITrackable Parse(string line) { var cells = line.Split(','); // If your array.Length is less than 3, something went wrong if (cells.Length < 3) { logger.LogWarning("Not enough values"); return(null); // Log that and return null } logger.LogInfo("Begin parsing"); TacoBell company = new TacoBell(); Point myTacoLocal = new Point(); double lat; double lon; if (!double.TryParse(cells[0], out lat) || !double.TryParse(cells[1], out lon)) { return(null); } if (Math.Abs(lon) > 180 || Math.Abs(lat) > 90) { return(null); } for (int i = 0; i < cells.Length; i++) { if (String.IsNullOrWhiteSpace(cells[i])) { if (cells[i].Length > 0) { logger.LogInfo("Incomplete Data"); return(null); } else { logger.LogFatal(null); return(null); } } else if (i == 0) { myTacoLocal.Latitude = double.Parse(cells[i]); } else if (i == 1) { myTacoLocal.Longitude = Convert.ToDouble(cells[i]); } else { company.SetName(cells[i]); } } company.SetLocation(myTacoLocal); return(company); // grab the latitude from your array at index 0 // grab the longitude from your array at index 1 // grab the name from your array at index 2 // Your going to need to parse your string as a `double` // which is similar to parsing a string as an `int` // You'll need to create a TacoBell class // that conforms to ITrackable // Then, you'll need an instance of the TacoBell class // With the name and point set correctly // Then, return the instance of your TacoBell class // Since it conforms to ITrackable // Do not fail if one record parsing fails, return null // TODO Implement }