import java.util.*; public class MiamiAnnualDataClient { //Data Source //http://www.weather.com/weather/wxclimatology/monthly/graph/USFL0316 public static void main(String[] args) { //Average monthly rainfall (inches) in Miami, FL double[] rainfall = {2.09, 2.42, 3.00, 3.20, 4.98, 8.27, 4.35, 6.37, 7.88, 4.47, 2.74, 2.05}; //Average monthly high temperatures (Fahr) in Miami, FL double[] meanHighTemps = {74.0, 75.0, 76.0, 79.0, 83.0, 87.0, 88.0, 89.0, 87.0, 84.0, 79.0, 76.0}; //Average monthly low temperatures (Fahr) in Miami, FL double[] meanLowTemps = {61.0, 63.0, 65.0, 69.0, 74.0, 77.0, 78.0, 79.0, 78.0, 75.0, 70.0, 64.0}; /* profileData(rainfall, "Rainfall(inches)"); profileData(meanHighTemps, "High Temperatures (Fahren.)"); profileData(meanLowTemps, "Low Temperatures (Fahren.)"); */ System.out.println(); System.out.println( dataProfile(rainfall, "Rainfall(inches)") + "\n\n" + dataProfile(meanHighTemps, "High Temperatures (Fahren.)") + "\n\n" + dataProfile(meanLowTemps, "Low Temperatures (Fahren.)") ); } //Display a Monthly data-set, with statistics private static void profileData(double[] data, String legend) { AnnualDataSet dataSet = new AnnualDataSet(data); String header = "Miami, FL Average Monthly " + legend; System.out.println("\n" + header + underline(header)); for (String month : AnnualDataSet.MONTHS) System.out.println(month.substring(0, 3) + " = " + dataSet.getData(month) ); System.out.println("Average: " + dataSet.average() ); System.out.println("Std Dev: " + dataSet.standardDeviation() ); //System.out.println("Median : " + dataSet.median() ); System.out.println("Highest: " + dataSet.maximum() + " in " + dataSet.monthOfMaximum()); System.out.println("Lowest : " + dataSet.minimum() + " in " + dataSet.monthOfMinimum()); } private static String dataProfile(double[] data, String legend) { AnnualDataSet dataSet = new AnnualDataSet(data); String profile = "Miami, FL Average Monthly " + legend; profile += "\n" + underline(profile) ; for (String month : AnnualDataSet.MONTHS) profile += "\n" + (month.substring(0, 3) + " = " + dataSet.getData(month) ); profile += "\n" + "Average: " + dataSet.average() + "\n" + "Std Dev: " + dataSet.standardDeviation() + "\n" + "Median : " + dataSet.median() + "\n" + "Highest: " + dataSet.maximum() + " in " + dataSet.monthOfMaximum() + "\n" + "Lowest : " + dataSet.minimum() + " in " + dataSet.monthOfMinimum() ; return profile; } private static String underline(String str) { String line = ""; for (int k = 1; k <= str.length(); k++) line += '-'; return line; } }