Skip to content

Commit

Permalink
feat(4.2.3): Finish U4_L2_Activity_Three
Browse files Browse the repository at this point in the history
  • Loading branch information
101zh committed Oct 25, 2023
1 parent 0b6a395 commit 16a9d20
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/main/java/Unit4/U4_L2_Activity_Three.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package Unit4;

import java.util.Scanner;

public class U4_L2_Activity_Three {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int anotherLocation = 1;
double largestLatitude = -90.0;
double largestLongitude = -180.0;
double smallestLatitude = 90.0;
double smallestLongitude = 180.0;

while (anotherLocation == 1) {
System.out.println("Please enter the longitude:");
double longitude = scanner.nextDouble();
System.out.println("Please enter the latitude:");
double latitude = scanner.nextDouble();

boolean longitudeIsValid = -180.0 <= longitude && longitude <= 180.0;
boolean latitudeIsValid = -90.0 <= latitude && latitude <= 90.0;

if (longitudeIsValid && latitudeIsValid) {
if (latitude > largestLatitude)
largestLatitude = latitude;
if (latitude < smallestLatitude)
smallestLatitude = latitude;

if (longitude > largestLongitude)
largestLongitude = longitude;
if (longitude < smallestLongitude)
smallestLongitude = longitude;

} else {
System.out.println("Incorrect Latitude or Longitude ");
}
System.out.println("Would you like to enter another location?");

anotherLocation = scanner.nextInt();
}

System.out.println("Farthest North: " + largestLatitude);
System.out.println("Farthest South: " + smallestLatitude);
System.out.println("Farthest East: " + largestLongitude);
System.out.println("Farthest West: " + smallestLongitude);

scanner.close();
}
}

0 comments on commit 16a9d20

Please sign in to comment.