Question: Write a class named GeoCoordinate that retains the longitude and latitude of an object on earth. Both longitude and latitude are represented as double values

 Write a class named GeoCoordinate that retains the longitude and latitudeof an object on earth. Both longitude and latitude are represented as

Write a class named GeoCoordinate that retains the longitude and latitude of an object on earth. Both longitude and latitude are represented as double values that must be in the range [-90.0, 90.0]. The class has the following constructors: bullet GeoCoordinate(), which initializes the latitude to 0.0 (the equator), the longitude to 0.0 (the prime meridian). GeoCoordinate() double longitude, double latitude): initializes the longitude and latitudes to values in [-90.0, 90.0]. The class has the following methods: bullet double getLongitude() and double getLatitude(), that return the longitude and latitude of the GeoCoordinate. boolean equals(GeoCoordinate g) that returns true if the GeoCoordinate of g and the current object represent the same GeoCoordinate, and false otherwise. boolean isWithinBounds(GeoCoordinate sw, GeoCoordinate ne) that takes exactly two GeoCoordinates representing the south-west and north-est vertices of a rectangular area (see Figure below), and returns true if the current coordinate is within the bounds of the area, and false otherwise. (This can be used to check whether a given vehicle for example has gone outside of a certain geographic area). Finally, the execution of the test program below, GeoCoordinateTest, should produce the following result: (20.0, 30.0) false true caught IllegalArgumentException: Wrong argument(s) upon construction of GeoCoordinate public class GeoCoordinateTest {public static void main(String [] args) {GeoCoordinate currentLocation; GeoCoordinate sw, ne; currentLocation = new GeoCoordinate (20.0, 30.0); sw = new GeoCoordinate (1 0.0. 10.0); ne = new GeoCoordinate (30.0. 30.0); System .out. println (currentLocation); System .out. println (currentLocation. equals (sw)); System. out. println (currentLocation. isWi thin Bounds (sw. ne)); try {GeoCoordinate wrongCoordinate = new GeoCoordinate(-100.0, 20.0);} catch (IllegalArgumentException e) {System .out.println ("caught IllegalArgumentException: " + e. getMessage());}}}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!