Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.54 KB | None | 0 0
  1. package ac.uk.napier.set07110Coursework;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5.  
  6. import org.openstreetmap.gui.jmapviewer.Coordinate;
  7.  
  8. import mapgui.MapGui;
  9. import weather.WeatherData;
  10.  
  11. /**
  12.  * QUESTION 13
  13.  *
  14.  * If you decide to answer question 13 then the main method below should be used as the entry point for your application
  15.  * You may use as many other classes as you feel necessary as long as all code is supplied
  16.  *
  17.  * Remember to add -Xmx1024m to the VM arguments using menu run --> run configurations in eclipse
  18.  */
  19. public class Answer13 {
  20.     static ArrayList<Double> temperature= new ArrayList<>();
  21.     public static void main(String[] args) {
  22.         System.out.println("Question 13");
  23.         /*
  24.          * Add your code below
  25.          */
  26.         doQuestion13();
  27.        
  28.     }  
  29.    
  30.     private static void doQuestion13(){
  31.         double station1Median =0;
  32.         double station2Median =0;
  33.         int stationId= 3316;
  34.         boolean flag = true;
  35.         ArrayList<Coordinate> coordinates = new ArrayList<>();
  36.         WeatherStationRetriever weatherStation = new WeatherStationRetriever(); //new weatherstation object
  37.         //temperature= weatherStation.getStationDetails(3316).
  38.        
  39.         while(flag) {
  40.            
  41.             for(int i=0; i<weatherStation.getStationDetails(stationId).getWeatherReadings().size(); i++) {
  42.                 temperature.add(weatherStation.getStationDetails(stationId).getWeatherReadings().get(i).getTemperature());
  43.                
  44.             }
  45.             Collections.sort(temperature);
  46.            
  47.             if(stationId ==3316) {
  48.                 station1Median = medianFinder(temperature.size());
  49.                 coordinates.add(new Coordinate(weatherStation.getStationDetails(stationId).getLat(), weatherStation.getStationDetails(stationId).getLon()));
  50.        
  51.  
  52.             }
  53.             if(stationId==3166) {
  54.                 station2Median = medianFinder(temperature.size());
  55.                 coordinates.add(new Coordinate(weatherStation.getStationDetails(stationId).getLat(), weatherStation.getStationDetails(stationId).getLon()));
  56.                 flag = false;
  57.             }
  58.             stationId= 3166;
  59.            
  60.            
  61.         }
  62.    
  63.  
  64.         double difference =station2Median-station1Median;
  65.         System.out.println("The difference in temperature is: " + Math.abs(difference) + " Degreees");
  66.         MapGui.showMap(coordinates);
  67.        
  68.        
  69.     }
  70.     public static double medianFinder(int listSize) {
  71.         double medianTemperature =0;
  72.        
  73.         if (listSize % 2 == 0)
  74.             medianTemperature = (temperature.get(temperature.size()/2) + temperature.get(temperature.size()/2 - 1))/2;
  75.         else {
  76.    
  77.             medianTemperature = (double)(temperature.size() - 1)/2;
  78.         medianTemperature = temperature.get((temperature.size()-1)/2);
  79.        
  80.  
  81.        
  82.     }
  83.        
  84.  
  85.                 return medianTemperature;
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement