Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started