I have some issues with a current exercise where I have to look up at an array of 1000 strings that are split by "," into siteId, siteName, year,month, day, hour and temperature. The information I need is an integer, which is the day when it was recorded, and a double which is the temperature.
For example,
I get a record from a weather station with the values 3031,LOCH GLACARNOCH SAWS (3031),2015,01,01,18,7.50
So far I have tried to make an arrayList and so with the dates, as there can be no duplicates, but In cannot find the solution to the question: How many days did the temperature fall to 0.0 or below anywhere in the UK?
The year variable is not so important as the records are only from 2015.
String[] weatherData = WeatherData.getData();
double zeroTemp = 0.0;
int counter = 0;
// get the data
for (int i = 1; i <= weatherData.length-1; i++) {
String line = weatherData[i];
String[] data = line.split(",");
int date = Integer.parseInt(data[6]);
int month = Integer.parseInt(data[5]);
int year = Integer.parseInt(data[4]);
double temp = Double.parseDouble(data[9]);
LocalDate when = LocalDate.of(year, month, date);
for(int j = 1; j<= data.length; j++) {
HashSet<LocalDate> duplicateDates = new HashSet<>(Arrays.asList(when));
System.out.println(when);
duplicateDates.add(when);
System.out.println(duplicateDates.size());
}
if(zeroTemp >= temp) {
counter++;
}
}
System.out.println("The temperature fell to 0.0 degrees or below in " + counter + " days.");
}