Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer the following with code below in Java: In this part of the lab you will write client code to manipulate some GeoLocation objects.

Please answer the following with code below in Java: In this part of the lab you will write client code to manipulate some GeoLocation objects. The GeoLocation class is being provided to you, so you don't have to write it. You will instead be writing code that constructs and manipulates three GeoLocation objects.
The popular TV series Breaking Bad made use of geographic location information. The Walter White character buried millions of dollars at a particular location in the desert outside of Albuquerque, New Mexico. He then bought a lottery ticket to help him remember that his stash was buried at a latitude of 34 degrees, 59 minutes, 20 seconds and a longitude of -106 degrees, 36 minutes, 52 seconds. Your client program will compute the distance between Walter's stash and the local FBI building and a local studio known as ABQ Studios (where Breaking Bad was filmed).
Your program should produce the following output:
The stash is at latitude: 34.988889, longitude: -106.614444
ABQ studio is at latitude: 34.989978, longitude: -106.614357
FBI building is at latitude: 35.131281, longitude: -106.61263
Distance in miles between:
stash/studio =0.07548768123801672
stash/fbi =9.849836190409732
Instructions:
Create a new Java class in NetBeans called GeoLocationClient. This class is a main class and should have a main method.
Create three GeoLocation objects with the values you see in the output above.
Print the three objects and call the distanceFrom method twice to get the desired output. Please note that the latitude/longitude information in the first three lines of output should be produced by calls to the GeoLocation's toString method, and the values in the final two lines of output should be produced by calls to the GeoLocation's distanceFrom method. code: package cis2087geolocation;
public class GeoLocation
{
public static final double RADIUS =3963.1676; // Earth radius in miles
private double latitude;
private double longitude;
// constructs a geo location object with given latitude and longitude
public GeoLocation(double inLatitude, double inLongitude){
latitude = inLatitude;
longitude = inLongitude;
}
// returns the latitude of this geo location
public double getLatitude(){
return latitude;
}
// returns the longitude of this geo location
public double getLongitude(){
return longitude;
}
// returns a string representation of this geo location
@Override
public String toString(){
return "latitude: "+ latitude +", longitude: "+ longitude;
}
// returns the distance in miles between this geo location and the given
// other geo location
public double distanceFrom(GeoLocation other){
double lat1= Math.toRadians(latitude);
double long1= Math.toRadians(longitude);
double lat2= Math.toRadians(other.latitude);
double long2= Math.toRadians(other.longitude);
// apply the spherical law of cosines with a triangle composed of the
// two locations and the north pole
double theCos = Math.sin(lat1)* Math.sin(lat2)+ Math.cos(lat1)* Math.cos(lat2)* Math.cos(long1- long2);
double arcLength = Math.acos(theCos);
double distance = arcLength * RADIUS;
return distance;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

More Books

Students also viewed these Databases questions