STATION NAME DATE TMAX TMIN 1 STATION 2 GHCND:USC00471667 CLINTON WI US 3 GHCND:
ID: 3702447 • Letter: S
Question
STATION NAME DATE TMAX TMIN 1 STATION 2 GHCND:USC00471667 CLINTON WI US 3 GHCND:USC00471667 CLINTON WI US 4 GHCND:USC00471667 CLINTON WI US 5 GHCND:USC00471667 CLINTON WI US 6 GHCND:USC00471667 CLINTON WI US 7 GHCND:USC00471667 CLINTON WI US 8 GHCND:USC00471667 CLINTON WI US 9 GHCND:USC00471667 CLINTON WI US 10 GHCND:USC00471667 CLINTON WI US 11 GHCND:USC00471667 CLINTON WI US 12 GHCND:USC00471667 CLINTON WI US 13 GHCND:USC00471667 CLINTON WI US 14 GHCND:USC00471667 CLINTON WI US 15 GHCND:USC00471667 CLINTON WI US 16 GHCND:USC00471667 CLINTON WI US 17 GHCND:USC00471667 CLINTON WI US 18 GHCND:USC00471667 CLINTON WI US 19 GHCND:USC00471667 CLINTON WI US 20 GHCND:USC00471667 CLINTON WI US 21 GHCND:USC00471667 CLINTON WI US 22 GHCND:USC00471667 CLINTON WI US 23 GHCND:USC00471667 CLINTON WI US 24 GHCND:USC00471667 CLINTON WI US 25 GHCND:USC00471667 CLINTON WI US AWND 20120101 20120102 20120103 20120104 20120105 20120106 20120107 20120108 20120109 20120110 20120111 20120112 20120113 20120114 20120115 20120116 20120117 20120118 20120119 56 N/A 83 N/A 67 139 N/A 128 N/A 56 N/A 28 N/A 28 N/A -78 N/A 50 N/A 56 N/A 28 N/A -44 N/A 44 106 N/A -72 117 N/A 167 N/A 22100 N/A -33 N/A 200 N/A 206 N/A 012012044-217 N/A 206 N/A 67 -178 N/A 44 N/A N/A 50 N/A 28 83 50 61 100 122 83 50 28 -139 20120121 20120122 20120123 20120124 -139Explanation / Answer
WeatherProcess.java
import java.io.*;
import java.util.*;
public class WeatherProcess {
public static void main(String[] args) {
//Block of all IO creation
File data = new File(args[0]);
File summary = new File(args[1]);
Scanner scnr = null;
PrintWriter pw = null;
try {
scnr = new Scanner(new FileReader(data));
}
catch(IOException ioe){
System.out.println("IOException happened while creating a Scanner with a FileReader.");
System.exit(1);
}
scnr.useDelimiter("[, ]+");
try{
pw = new PrintWriter(new FileWriter(summary));
}
catch(IOException ioe){
System.out.println("IOException happened while creating a PrintWriter with a FileWriter.");
System.exit(1);
}
//Placing first line in Summary File
pw.print("STATION,STATION_NAME,DATE,TAVG,AVGWNDCHL");
//Skipping over the first line
scnr.nextLine();
//Analysis of file)
String currStationID = scnr.next();
String currStation = scnr.next();
String stationCheck = currStation;
while(scnr.hasNext()) {
while(currStation == stationCheck) {
int currDate = scnr.nextInt();
int currYearMonth = (currDate / 100);//double check to make sure that this is the correct way to get month
int dateCheck = currYearMonth;
double avgTemp = 0;
int tempCounter = 0;
double avgWndChll = 0;
int wndChllCounter = 0;
while(currYearMonth == dateCheck && currStation == stationCheck) {
int maxTemp;
int minTemp;
double avgFTemp;
int fCounter = 0;
int windSpeed;
try{
maxTemp = scnr.nextInt();
++fCounter;
}
catch(InputMismatchException ime) {
maxTemp = 0;
}
try{
minTemp = scnr.nextInt();
++fCounter;
}
catch(InputMismatchException ime) {
minTemp = 0;
}
if(fCounter > 0) {
avgFTemp = ((maxTemp + minTemp) / fCounter) * (9/5) + 32;
avgTemp += avgFTemp;
++tempCounter;
try{
windSpeed = scnr.nextInt();
++wndChllCounter;
avgWndChll += 35.74 + 0.6215 * avgFTemp - 35.75 Math.pow(windSpeed, 0.16) + 0.4275 * avgFTemp * Math.pow(windSpeed, 0.16);
}
catch(InputMismatchException ime) {
}
}
}
pw.print(currStationID + "," + currStation + "," + currDate + ",");
if(tempCounter > 0) {
//pw.print("" + (avgTemp / tempCounter) + ",");
}
else {pw.print("N/A,");}
if(wndChllCounter > 0) {
//pw.println(averageWindChill);
}
else{pw.println("N/A");
}
}
}
//Closing all inputs and outputs
scnr.close();
pw.close();
//Closing program
System.exit(0);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.