Advertisement
apez1

Term 1: Lesson 20 - Coding Activity

Sep 24th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. /*
  2.  * find the largest number in an array arlat and arlon
  3.  * remove a number from the array if out of range
  4.  */
  5.  
  6. package project;
  7.  
  8. import java.util.*;
  9. import java.util.Scanner;
  10. import java.util.Collections;
  11.  
  12. public class Yourmom {
  13.  
  14.     public static void main(String[] args) {
  15.        
  16.         double lat;
  17.         double lon;
  18.         int reply = 1;
  19.        
  20.         ArrayList <Double> arlat = new ArrayList<Double>();
  21.         //double arlat[] = new double[7];
  22.         //double arlon[] = new double[7];
  23.         ArrayList <Double> arlon = new ArrayList<Double>();
  24.  
  25.  
  26.         Scanner scanner = new Scanner(System.in);
  27.            
  28.         while(reply != 0) {
  29.            
  30.         int c = 0;
  31.         c++;   
  32.         System.out.println("Please enter the latitude:");
  33.         lat = scanner.nextDouble();
  34.         //arlat[c]=lat;
  35.         arlat.add(lat);
  36.        
  37.         System.out.println("Please enter the longitude:");
  38.         lon = scanner.nextDouble();
  39.         //arlon[c]=lon;
  40.         arlon.add(lon);
  41.        
  42.         int flag = 0;
  43.        
  44.         if(lat < -90 || lat > 90 ) {
  45.             flag = 1;      
  46.         }
  47.         if(lon < -180 || lon > 180 ) {
  48.             flag = 1;      
  49.         }
  50.    
  51.         if(flag == 1) {
  52.             System.out.println("Incorrect Latitude or Longitude");
  53.             reply = 1;
  54.             //remove numbers from array
  55.             arlon.remove(lon);
  56.             arlat.remove(lat);
  57.  
  58.         }
  59.            
  60.         if(flag != 1) {
  61.             System.out.println("Would you like to enter another location?");
  62.             reply = scanner.nextInt();                 
  63.             }  
  64.         }
  65.        
  66.        
  67.         double largestlat = Collections.max(arlat);
  68.         double smallestlat = Collections.min(arlat);
  69.  
  70.         double largestlon = Collections.max(arlon);
  71.         double smallestlon = Collections.min(arlon);
  72.        
  73.                    
  74.         if(reply ==0) {        
  75.             System.out.println("Farthest North: " + largestlat);
  76.             System.out.println("Farthest South: " + smallestlat);       //*
  77.            
  78.             System.out.println("Farthest East: " + largestlon) ;
  79.             System.out.println("Farthest West: " + smallestlon);        //*
  80.            
  81.                
  82.         }  
  83.  
  84.     }  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement