Created
August 6, 2017 13:24
-
-
Save kimki1124/aac50fe44ee752278e69ba8a2946d244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static double bestPracticeMean(String town, String strng) { | |
return parseTemp(town, strng).stream() | |
.collect(averagingDouble(n -> n)); | |
} | |
public static double bestPracticeVariance(String town, String strng) { | |
double mean = mean(town, strng); | |
if (mean == -1.0) return -1.0; | |
return parseTemp(town, strng).stream() | |
.collect(averagingDouble(n -> (n - mean) * (n - mean))); | |
} | |
private static List<Double> parseTemp(String town, String strng) { | |
List<Double> temps = new ArrayList<>(); | |
for (String line : strng.split("\\n")) { | |
String[] data = line.split(":"); | |
if (town.equals(data[0])) { | |
for (String weather : data[1].split(",")) { | |
String[] temp = weather.split("\\s"); | |
temps.add(Double.parseDouble(temp[1])); | |
} | |
break; | |
} | |
} | |
if (temps.isEmpty()) temps.add(-1.0); | |
return temps; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment