# Untitled

unknown
plain_text
2 months ago
2.6 kB
12
Indexable
Never
```/* Lesson 2 Coding Activity Question 3 */

import java.util.Scanner;

public class U4_L2_Activity_Three
{
public static void main(String[] args)
{
/*
Milestone 1: Set up a scanner and an int variable to hold the answer to the question "Would you like to enter another location?". Write a while loop based on this variable and add code to it which asks this question and gets an int response from the user.

the idea is to compare the new lang to the old lang and whichever furthest continues
and loops
need to have 2 values at the end of both lon and lat, 1 furthest in each direction so 4 in total.

Farthest North - maximum latitude
Farthest South - minimum latitude
Farthest East - maximum longitude
Farthest West - minimum longitude

If an invalid pair of coordinates is entered, then the program should print "Incorrect latitude or longitude." A latitude value is invalid if it is not between -90 and 90 inclusive. A longitude value is invalid if it is not between -180 and 180 inclusive.
*/

double lon = 0.0;
double lat = 0.0;
double newLon = 0.0;
double newLat = 0.0;

double northLat = 0.0;
double southLat = 0.0;
double westLon = 0.0;
double eastLon = 0.0;

int n1 = 1;
Scanner kb = new Scanner(System.in);

lon = kb.nextDouble();
lat = kb.nextDouble();
if ((lon > 180 || lon < -180) || (lat > 90 || lat < -90)){
System.out.println("Incorrect latitude or longitude.");

}
while(n1 == 1){
System.out.println("Would you like to enter another location?");
n1 = kb.nextInt();
newLon = kb.nextDouble();
newLat = kb.nextDouble();

if ((newLon > 180. || newLon < -180) || (newLat > 90 || newLat < -90)){
System.out.println("Incorrect latitude or longitude.");
}

if (newLon > lon){
westLon = lon;
eastLon = newLon;
}
else{
eastLon = lon;
westLon = newLon;
}
if (newLat > lat){
southLat = lat;
northLat = newLat;
}
else{
northLat = lat;
southLat = newLat;
}
}
System.out.printf("Farthest North: %.2f", northLat);
System.out.printf("Farthest South: %.2f", southLat);
System.out.printf("Farthest East: %.2f", eastLon);
System.out.printf("Farthest West: %.2f", westLon);
}
}```