Question
Question 01 : Write a Java program that prompts for and reads the latitude of a location on earth in the format: integerDegrees integerMinutes doubleSeconds
Question 01: Write a Java program that prompts for and reads the latitude of a location on earth in the format:
integerDegrees integerMinutes doubleSeconds characterPosition
where characterPosition is either N, n, S or s. If the input is valid your program converts the input latitude to decimal degrees where North latitudes are +ve, and South latitudes are ve.
26 13 15.272400 N | 26.220909 |
50 11 55.024800 S | -50.198618 |
25 44 36.97 s | -25.743603 |
43 10 23.49 n | 43.173192 |
:
Your program must recover from InputMismatchException.
Your program must recover from invalid latitude input.
Your program must use the following private static methods:
isValidLatitude that returns true if the five input values form a valid latitude; otherwise it returns false.
getDecimalDegrees that returns the decimal degree of the five input values.
Your program must be general and it must behave as in the sample program runs below.
:
A latitude can have values from 0 degrees to 90 degrees inclusive, i.e, 0 ? degrees ? 90
1 degree = 60 minutes, 1 minute = 60 seconds.
A minute can have values in the interval [0 . . . 60), i.e., 0 ? minutes
A second can have values in the interval [0 . . . 60), i.e., 0 ? seconds
Sample Program runs:
Enter the latitude: 50.0 60.0 45.0000 N Error: java.util.InputMismatchException Enter the latitude: 120 27 58.64320 S Erro Invalid latitude Enter the latitude: 30 50 20.67320 W Erro Invalid latitude Enter the latitude: 26 13 15.272400 N Decimal latitude: 26.220909Step 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