Question: place_information.py For this part of the assignment, you will write a class called PlaceInformation that stores information about a place of interest. It should have
place_information.py
For this part of the assignment, you will write a class called PlaceInformation that stores information about a place of interest. It should have the following public methods:
__init__(name, address, tag, latitude, longitude) get_name() get_address() get_tag() __str__() get_location() distance_from(spot) # spot is a GeoLocation object
The first three get methods simply return the values that were provided when the object was constructed. The str method should return the name followed by the location details inside parentheses (location details should formatted the same as in the str method for GeoLocation). Although the constructor takes a latitude and longitude, you should store this information inside the PlaceInformation object using a GeoLocation object. The get_location method should return a reference to this GeoLocation object. Remember that in writing your class, you dont want to include code that appears elsewhere. For example, your GeoLocation object knows how to compute a distance, so you should not be repeating the code for computing distances in your PlaceInformation class. You should instead be asking the GeoLocation object to perform the computation. Be sure to properly encapsulate your object with private fields.
Your teacher is providing a client program called place_information_client.py that can be used to test your class. It is in the repository for this assignment.
# This program constructs several PlaceInformation objects and prints # information about them and the distances between them and two locations # (London and Kane Hall). It is intended to be used to test whether the # PlaceInformation class is implemented correctly. from place_information import * from geolocation import * def main(): data = [PlaceInformation("Mount Lemmon", "Tucson", "tourist, park", 32.44380, -110.77134), PlaceInformation("Student Union Building", "University of Arizona campus", "restaurant", 32.23262, -110.95206), PlaceInformation("Gould-Simpson Hall", "University of Arizona campus", "university, ua", 32.22976, -110.95501)] london = GeoLocation(51.5112139, -0.1198244) old_main = GeoLocation(32.23189, -110.95342) for info in data: print("name : " + info.get_name()) print("address : " + info.get_address()) print("tags : " + info.get_tag()) print("__str__ : " + str(info)) print("London : " + str(info.distance_from(london))) print("Old Main: " + str(info.distance_from(old_main))) print() main() # This class stores information about a location on Earth. Locations are # specified using latitude and longitude. The class includes a method for # computing the distance between two locations. from math import * RADIUS = 3963.1676 # Earth radius in miles class GeoLocation: # constructs a geo location object with given latitude and longitude def __init__(self, latitude, longitude): self.__latitude = float(latitude) self.__longitude = float(longitude) # returns the latitude of this geo location def get_latitude(self): return self.__latitude # returns the longitude of this geo location def get_longitude(self): return self.__longitude # returns a string representation of this geo location def __str__(self): return "latitude: " + str(self.__latitude) + ", longitude: " + str(self.__longitude) # WRITE THIS METHOD FOR AN A # returns the distance in miles between this geo location and the given # other geo location # # YOU NEED TO WRITE THIS METHOD; def distance_from(self, other): return theAnswer
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
