CS1083/Submissions/As6/IsaacShoebottom_As6_Archive/TemperatureStats.java

44 lines
1.2 KiB
Java
Raw Permalink Normal View History

2022-10-07 00:44:12 -03:00
/**
* 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);
}
}