Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ac.uk.napier.set07110Coursework;
- import java.util.ArrayList;
- import java.util.Collections;
- import org.openstreetmap.gui.jmapviewer.Coordinate;
- import mapgui.MapGui;
- import weather.WeatherData;
- /**
- * QUESTION 13
- *
- * If you decide to answer question 13 then the main method below should be used as the entry point for your application
- * You may use as many other classes as you feel necessary as long as all code is supplied
- *
- * Remember to add -Xmx1024m to the VM arguments using menu run --> run configurations in eclipse
- */
- public class Answer13 {
- static ArrayList<Double> temperature= new ArrayList<>();
- public static void main(String[] args) {
- System.out.println("Question 13");
- /*
- * Add your code below
- */
- doQuestion13();
- }
- private static void doQuestion13(){
- double station1Median =0;
- double station2Median =0;
- int stationId= 3316;
- boolean flag = true;
- ArrayList<Coordinate> coordinates = new ArrayList<>();
- WeatherStationRetriever weatherStation = new WeatherStationRetriever(); //new weatherstation object
- //temperature= weatherStation.getStationDetails(3316).
- while(flag) {
- for(int i=0; i<weatherStation.getStationDetails(stationId).getWeatherReadings().size(); i++) {
- temperature.add(weatherStation.getStationDetails(stationId).getWeatherReadings().get(i).getTemperature());
- }
- Collections.sort(temperature);
- if(stationId ==3316) {
- station1Median = medianFinder(temperature.size());
- coordinates.add(new Coordinate(weatherStation.getStationDetails(stationId).getLat(), weatherStation.getStationDetails(stationId).getLon()));
- }
- if(stationId==3166) {
- station2Median = medianFinder(temperature.size());
- coordinates.add(new Coordinate(weatherStation.getStationDetails(stationId).getLat(), weatherStation.getStationDetails(stationId).getLon()));
- flag = false;
- }
- stationId= 3166;
- }
- double difference =station2Median-station1Median;
- System.out.println("The difference in temperature is: " + Math.abs(difference) + " Degreees");
- MapGui.showMap(coordinates);
- }
- public static double medianFinder(int listSize) {
- double medianTemperature =0;
- if (listSize % 2 == 0)
- medianTemperature = (temperature.get(temperature.size()/2) + temperature.get(temperature.size()/2 - 1))/2;
- else {
- medianTemperature = (double)(temperature.size() - 1)/2;
- medianTemperature = temperature.get((temperature.size()-1)/2);
- }
- return medianTemperature;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement