Reference no: EM13165024
Write a program that will create three city objects (described below) containing name,longitude, and latitude information. The information for the cities will be displayed along with the distance betweenthe cities.The requirements are s follows:
- Define a class named City which will contain the following:
o A String name field
o A double longitude field
o A double latitude field
o A constructor that takes the name,longitude,and latitude as parameters.
o Setter and getter methods for all fields.
o A method with the signature public double distanceFrom(City otherCity) that will calculate and return the distance
between one city and the other city using the standard distance formula sqrt((x1-x2)2 + (y1-y2)2).
o A method with the signature public void displayDetails() that will write the details of the city to the console.
Refer to the example output below.
- Define a class named LastnameHw4 which will contain the following:
o A main method
o A City[] cities field
o A method with the signature public static void printDistances(City[] cities) that will iterate through the cities andprint the distance between the city and all other cities using the distanceFrom(...) method.Be sure not to print thedistance from a city to itself as the result would always be 0.
Refer to the example output below.
o A method with the signature public static void printDetails(City[] cities) that will iterate through the cities and printthe details of the city using the displayDetails(...) method.
- The main method will do the following:
o Create three cities and store them in the cities array field.
o Call the printDetails(..) method to display the details of the cities.
o Call the printDistances(...) method to display the distances between the cities.
Be sure to use proper coding conventions including indentation, constants,and
Computer Science