public ITrackable Parse(string line) { logger.LogInfo("Begin parsing"); // Take your line and use line.Split(',') to split it up into an array of strings, separated by the char ',' var cells = line.Split(','); // If your array.Length is less than 3, something went wrong if (cells.Length < 3) { // Log that and return null // Do not fail if one record parsing fails, return null return(null); // TODO Implement } // grab the latitude from your array at index 0 double latitude = double.Parse(cells[0]); // grab the longitude from your array at index 1 double longitude = double.Parse(cells[1]); // grab the name from your array at index 2 var name = cells[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 var point = new Point(); point.Latitude = latitude; point.Longitude = longitude; var tacoBell = new Tacobell(); tacoBell.Name = name; tacoBell.Location = point; // Then, return the instance of your TacoBell class // Since it conforms to ITrackable return(tacoBell); }
static void Main(string[] args) { // TODO: Find the two Taco Bells that are the furthest from one another. // HINT: You'll need two nested forloops --------------------------- logger.LogInfo("Log initialized"); // 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 var lines = File.ReadAllLines(csvPath); logger.LogInfo($"Lines: {lines[0]}"); // Create a new instance of your TacoParser class var parser = new TacoParser(); // Grab an IEnumerable of locations using the Select command: var locations = lines.Select(parser.Parse); var locations = lines.Select(parser.Parse).ToArray(); // DON'T FORGET TO LOG YOUR STEPS // Now that your Parse method is completed, START BELOW ---------- // TODO: Create two `ITrackable` variables with initial values of `null`. These will be used to store your two taco bells that are the farthest from each other. // Create a `double` variable to store the distance ITrackable tacoBellOne = new Tacobell(); ITrackable tacoBellTwo = new Tacobell(); double dist = 0; // Include the Geolocation toolbox, so you can compare locations: `using GeoCoordinatePortable;` //HINT NESTED LOOPS SECTION--------------------- // Do a loop for your locations to grab each location as the origin (perhaps: `locA`) for (var i = 0; i < locations.Length; i++) { //done var corA = new GeoCoordinate(); var locA = locations[i]; // Create a new corA Coordinate with your locA's lat and long corA.Longitude = locA.Location.Longitude; corA.Latitude = locA.Location.Latitude; // nested loop to get the second location for (var a = 0; a < locations.Length; a++) { // create locB var locB = locations[a]; var corb = new GeoCoordinate(); corb.Longitude = locB.Location.Longitude; corb.Latitude = locB.Location.Latitude; if (corA.GetDistanceTo(corb) > dist) { dist = corA.GetDistanceTo(corb); tacoBellOne = locA; tacoBellTwo = locB; } } // ^^^^^^ // |||||| // 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 farthest away from each other. logger.LogInfo($"The distance between {tacoBellOne.Name} and {tacoBellTwo.Name} is {dist} and its the furthest 2 TacoBells! "); }
static void Main(string[] args) { // DON'T FORGET TO LOG YOUR STEPS // Grab the path from the name of your file logger.LogInfo("Log initialized"); // use File.ReadAllLines(path) to grab all the lines from your csv file var lines = File.ReadAllLines(csvPath); // Log and error if you get 0 lines and a warning if you get 1 line logger.LogInfo($"Lines: {lines[0]}"); // Create a new instance of your TacoParser class var parser = new TacoParser(); // Grab an IEnumerable of locations using the Select command: var locations = lines.Select(parser.Parse); var locations = lines.Select(parser.Parse).ToArray(); // 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. ITrackable tacoBell1 = null; ITrackable tacoBell2 = null; // Create a `double` variable to store the distance double distance = 0; // Do a loop for your locations to grab each location as the origin (perhaps: `locA`) (first for loop) // 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`) (second for loop) // 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 GeoCoordinate corA = new GeoCoordinate(); GeoCoordinate corB = new GeoCoordinate(); var locA = new Tacobell(); var locB = new Tacobell(); for (int i = 0; i < locations.Length; i++) { corA.Latitude = locations[i].Location.Latitude; corA.Longitude = locations[i].Location.Longitude; for (int j = 0; j < locations.Length; j++) { corB.Latitude = locations[j].Location.Latitude; corB.Longitude = locations[j].Location.Longitude; if (corA.GetDistanceTo(corB) > distance) { distance = corA.GetDistanceTo(corB); locA.Name = locations[i].Name; locB.Name = locations[j].Name; } } } Console.WriteLine($"{locA.Name} and {locB.Name}"); // Once you've looped through everything, you've found the two Taco Bells furthest away from each other. // TODO: Find the two Taco Bells in Alabama that are the furthest from one another. // HINT: You'll need two nested forloops }