44 lines
1.2 KiB
Java
44 lines
1.2 KiB
Java
/**
|
|
* Temperature statistics on a csv file, a driver class
|
|
* @author Isaac Shoebottom (3429069)
|
|
*/
|
|
|
|
public class TemperatureStats {
|
|
public static void main(String[] args) {
|
|
|
|
String maxDate = null, minDate = null;
|
|
double maxTemp = 0, minTemp = 0;
|
|
int counter = 0;
|
|
|
|
if (args.length == 0) {
|
|
System.out.println("Usage: java TemperatureStats file.csv");
|
|
System.exit(1);
|
|
}
|
|
|
|
TemperatureParser tp = new TemperatureParser(args[0]);
|
|
|
|
while (tp.parseHasNext()) {
|
|
tp.parseLine();
|
|
|
|
if (counter == 0) {
|
|
maxDate = tp.getDate();
|
|
minDate = maxDate;
|
|
maxTemp = tp.getTemperature();
|
|
minTemp = maxTemp;
|
|
}
|
|
else if (tp.getTemperature() < minTemp) {
|
|
minTemp = tp.getTemperature();
|
|
minDate = tp.getDate();
|
|
}
|
|
else if (tp.getTemperature() > maxTemp) {
|
|
maxTemp = tp.getTemperature();
|
|
maxDate = tp.getDate();
|
|
}
|
|
counter++;
|
|
}
|
|
|
|
System.out.println("Maximum: " + maxDate + ": " + maxTemp);
|
|
System.out.println("Minimum: " + minDate + ": " + minTemp);
|
|
}
|
|
}
|