The latitude, longitude and place name are used to label a map. Implement a class with latitude and longitude as decimal degrees (33.755, for example) and a place name. Provide two constructors, one has three parameters place name, latitude and longitude in decimal degrees and the other has 7 parameters: place name, latitude degrees, latitude minutes, latitude seconds, longitude degrees, longitude minutes, longitude seconds. An example statement used to create an object is:
MapLabels label1 = new MapLabels("Atlanta, GA",33, 45, 18, -84, 23, 24, 37, 46, 45.48, -122, 25, 9.12);The position in degrees, minutes and seconds can be converted to decimal degrees using this formula. We will learn more about the
Math
methods in Chapter 4.
decimalDegress = Math.signum(degrees) * (Math.abs(degrees) + minutes/60. + seconds/3600.);Provide a toString method that will return an XML string with the values in this format:
<label name="Atlanta, GA" latitude="33.755" longitude="-84.39"/> <label name="San Francisco, CA" latitude="37.7793" longitude="-122.4192"/>