Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have homework about java programthis is the question please answer it I need the code answer 2. The straight-line distance in kilometers between two

I have homework about java programthis is the question please answer it I need the code answer

image text in transcribed

image text in transcribed

2. The straight-line distance in kilometers between two locations on earth can be computed by the following two formulas: w = sin(LatitudebifferenceInRadians + cos(Latitude1_in_radians) cos(Latitude2_in_radians) Longitude DifferenceInRadians sina distance = earth RadiusInKilometers . 2 . atan2(VwV1-W) Where: earthRadiusinKilometers = 6371 km LatitudeDifferencelnRadians = Latitude 1 in radians - Latitude2 in radians LongitudeDifferencein Radians = Longitudel_in_radians - Longitude2_in_radians Write a java program that prompts for and reads the longitudes and latitudes of two locations on earth. If the input is invalid your program must display an appropriate error message and terminate; otherwise it computes and displays the straight-line distance, in kilometers, between the two locations. Please notice the following: Your longitude input for each location must be four values: integer Degrees integer Minutes double Seconds character Position where character Position is either E or W Your latitude input for each location must be four values: integer Degrees integer Minutes doubleSeconds where character Position is either N or S character Position Your program must convert each input to decimal degrees, where East longitudes are +ve, West longitudes are -ve, North latitudes are +ve, and South latitudes are -ve. The format of the program output must be similar to the given examples. . Examples: input Decimal degrees 26 13 15.272400 N 26.220909 50 11 55.024800 E 50.198618 25 44 36.97 S -25.743603 43 10 23.49 W -43.173192 . Your program must use appropriate constants. Note: Your program must be general and it must behave as in the sample program runs below: Hint: A longitude can have values from 0 degrees to 180 degrees inclusive, i.e., 05 degrees s 180 A latitude can have values from 0 degrees to 90 degrees inclusive, i.e, os degrees s 90 1 degree = 60 minutes, 1 minute = 60 seconds. A minute can have values in the interval [0...60), i.e., 0 s minutes

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

International Baccalaureate Computer Science HL And SL Option A Databases Part I Basic Concepts

Authors: H Sarah Shakibi PhD

1st Edition

1542457084, 978-1542457088

More Books

Students also viewed these Databases questions