The program - GEO POINTS AS A CLASS - defines a class to keep track of a point in space, its description, and provides it the capability to figure out its distance from another point. The program reuses some of the previous GEO POINTS program ( refers to MlengelaPD5).
- The program defines a class called GeoPoint that will have the following:
- A constructor init (self) method that will set two attributes(variables) called self.lat, self.lon for the location of the point. The init method will also initialize a description attribute(variable) that will start as the empty string " ".
- A SetPoint(self) method that will set the values of self.lat, self. lon.
- A GetPoint(self) method that will tuple or list with self.lat, self. lon.
- A CalcDistance(_self, lat, lon) method that will figure out the distance between the object's self. lat, self. lon and lat, lon parameters passed in.
- A SetDescription (_self, description) method that will set the object's self.description attribute (variable).
- A GetDescription(self) method that will return the object's self.description attribute.
- In the "main" part of the program, there are the following:
- Instantiate two points. i.) Use the SetPoint and SetDescription methods to set the points location and description. Make sure they have different coordinates and different descriptions. It should look something like the following, but with your own coordinates and description: point1 = Geopoint() point1.SetPoint((25.25, 52.52)) point1.SetDescription("Loc2")
- Inside a "Do another (y/n)?" loop, do the following: i.) Ask the user for their location. The program asks for coordinates in three inputs, or asks them for their coordinates in one input with each element separated by a comma. ii.) Use point1 and point2's CalcDistancePoint method to find the distance from each point to the user's location. Notice we are passing in the user's point rather than the separate coordinates: distanceToOne=point1.CalcDistancePoint(userLat, userLon) distanceToTwo=point2.CalcDistancePoint(userLat, userLon) iii.) Tell the user which point they are closest to in this format: You are closest to < description>, which is located at <point's lat and lon coordinates> iv.) Ask "Do another(y/n) and loop if they respond with 'y'