public ITrackable Parse(string line) { // split line into array of strings string[] cells = line.Split(','); // Do not fail if one record parsing fails, return null if (cells.Length < 3) { logger.LogError(line); return null; } // converting latitude and longitude to double double latitude = double.Parse(cells[0]); double longitude = double.Parse(cells[1]); if (latitude > 180 || longitude > 180) { logger.LogError(line, null); return null; } string locationName = cells[2]; Point coordinates = new Point(); coordinates.Latitude = latitude; coordinates.Longitude = longitude; TacoBell tacoBell = new TacoBell(); tacoBell.Name = locationName; tacoBell.Location = coordinates; return tacoBell; }
public ITrackable Parse(string line) { logger.LogInfo("Begin parsing"); if (line == null) { logger.LogWarning("Line was null"); return(null); } // 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 || cells.Length > 3) { logger.LogError("Array length is less than 3", new System.Exception()); // 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 var lat = cells[0]; // grab the longitude from your array at index 1 var lon = cells[1]; // grab the name from your array at index 2 var name = cells[2]; Console.WriteLine("Latitude:" + (lat)); Console.WriteLine("Longitude:" + (lon)); Console.WriteLine("Name:" + (name)); // Your going to need to parse your string as a `double` var doublelot = double.Parse(lat); var doublelon = double.Parse(lon); // which is similar to parsing a string as an `int` // You'll need to create a TacoBell class // that conforms to ITrackable TacoBell tacobell = new TacoBell(); // Then, you'll need an instance of the TacoBell class // With the name and point set correctly var point = new Point(); point.Latitude = doublelot; point.Longitude = doublelon; TacoBell tacoBell = new TacoBell(); tacoBell.Name = name; tacoBell.Location = point; // Then, return the instance of your TacoBell class // Since it conforms to ITrackable return(tacoBell); }
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 var lat = cells[0]; // grab the longitude from your array at index 1 var log = 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` var dLatitude = Double.Parse(lat); // which is similar to parsing a string as an `int` var dLongitude = Double.Parse(log); var tacoPoint = new Point(); tacoPoint.Latitude = dLatitude; tacoPoint.Longitude = dLongitude; ; // You'll need to create a TacoBell class // that conforms to ITrackable // TACOBELL CLASS COMPLETE // Then, you'll need an instance of the TacoBell class var bell = new TacoBell(name, tacoPoint); // With the name and point set correctly // Then, return the instance of your TacoBell class // Since it conforms to ITrackable return(bell); }
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 logger.LogError("Array length is less than 3", null); // Do not fail if one record parsing fails, return null return(null); // TODO Implement } var latitude = cells[0]; // grab the latitude from your array at index 0 var longitude = cells[1]; // grab the longitude from your array at index 1 var locationName = cells[2]; // 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` var dublatitude = double.Parse(latitude); var dublongitude = double.Parse(longitude); // You'll need to create a TacoBell class // that conforms to ITrackable var _tacoBell = new TacoBell(); // Then, you'll need an instance of the TacoBell class // With the name and point set correctly var point = new Point(); point.Latitude = dublatitude; point.Longitude = dublongitude; _tacoBell.Location = point; _tacoBell.Name = locationName; return(_tacoBell); // Then, return the instance of your TacoBell class // Since it conforms to ITrackable //return null; }
public ITrackable Parse(string line) { if (string.IsNullOrEmpty(line)) { _logger.LogWarning("String was empty or null"); return(null); } var cells = line.Split(','); if (cells.Length < 2) { _logger.LogWarning("Missing Longitude or Latitude"); return(null); } try { var longitude = double.Parse(cells[0]); var latitude = double.Parse(cells[1]); var name = (cells.Length == 3) ? cells[2] : ""; if (Math.Abs(longitude) > Point.MaxLon || Math.Abs(latitude) > Point.MaxLat) { _logger.LogWarning("Longitude or Latitude out of bounds"); return(null); } var point = new Point { Longitude = longitude, Latitude = latitude }; var taco = new TacoBell { Name = name, Location = point }; return(taco); } catch (Exception e) { _logger.LogError("Longitude or Latitude were not a valid number", e); return(null); } }
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(); var locations = lines.Select(line => parser.Parse(line)).ToArray(); ITrackable location1 = new TacoBell(); ITrackable location2 = new TacoBell(); double distance = 0; for (int i = 0; i < locations.Length; i++) { var locA = locations[i]; var corA = new GeoCoordinate(); corA.Latitude = locA.Location.Latitude; corA.Longitude = locA.Location.Longitude; for (int j = 0; j < locations.Length; j++) { var locB = locations[j]; var corB = new GeoCoordinate(locB.Location.Latitude, locB.Location.Longitude); if (corA.GetDistanceTo(corB) > distance) { distance = corA.GetDistanceTo(corB); location1 = locA; location2 = locB; } } } var distanceInMile = Math.Round(distance * .0006231, 2); Console.WriteLine($" {location1.Name} and {location2.Name} are {distanceInMile} miles apart"); }