Figure out the the number of days with skiable snow in the years specified from the data file.?
-
http://www.cs.usm.maine.edu/~welty/cos160/160Sp2012/Program9/Program9.html I'm stuck on problem 4a-c. this is my code so far.. PLEASE HELP!! import java.io.*; import java.util.Scanner; public class weatherPortland { // main method that uses a Scanner input to load the appropriate file, // and calls other on other methods as well. public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("PortlandWeather.txt")); dataRecords(input); } // This method uses a while loop that inputs each line and counts them as they go by // and at the end it subtracts one line because of the header, it then prints the number // and calls the method "holdData" private static int dataRecords(Scanner input) throws FileNotFoundException { int line = 0; int records = 0; while (input.hasNextLine()) { input.nextLine(); line++; records = line - 1; } System.out.println("Total number of days recorded: " + records); input.close(); holdData(records, input); return line; } // this method uses a while loop that will hold the data contained inside the text file. // The storeInfo variable is used to access these arrays and as long as there is an input it will keep going. private static void holdData(int count, Scanner input) throws FileNotFoundException { Scanner input2 = new Scanner(new File("PortlandWeather.txt")); // input2.nextLine(); int storeInfo = 0; // holds info for all the arrays below. // declares all the arrays and sets them to the type int. int[] year = new int[count]; int[] month = new int[count]; int[] day = new int[count]; int[] tmin = new int[count]; int[] tmax = new int[count]; int[] prcp = new int[count]; int[] snow = new int[count]; int[] snwd = new int[count]; do { String line = input2.nextLine(); // get a line from the file Scanner lineScanner = new Scanner(line); // make a scanner for this line lineScanner.useDelimiter("[/,\\s]+"… // change the delimiter to slash, comma, or space // apply's the storedInfo variable to each declared array. year[storeInfo] = lineScanner.nextInt(); month[storeInfo] = lineScanner.nextInt(); day[storeInfo] = lineScanner.nextInt(); tmin[storeInfo] = lineScanner.nextInt(); tmax[storeInfo] = lineScanner.nextInt(); prcp[storeInfo] = lineScanner.nextInt(); snow[storeInfo] = lineScanner.nextInt(); snwd[storeInfo] = lineScanner.nextInt(); storeInfo++; } while (input2.hasNext()); System.out.println(""); countSkiDays(snow, day); System.out.println(""); } // this method calculates the total number of days it snowed and if the // if the snow fall is anything 4 or greater it counted it as a ski day. private static double countSkiDays(int[] snow, int[]day ) { int snowed = 0; int skiDays = 0; for (int i = 1; i < snow.length; i++) { snowed = snow[i]; if (snowed >= 4) { skiDays++; } } System.out.println("The number of days with skiable snow in the years from 1920 to 2008 was: " + skiDays + "."); return snowed; } }
-
Answer:
You're a little off on 4-A http://pastebin.com/8NzcC7Wm But I am assuming your answer of 1956 is correct. If not, http://pastebin.com/v2JLkULU I think is correct Waiting on the GF to get ready, so boredom made me do part B http://pastebin.com/rUPvSEnt I've done 4-C, but won't give it unless you show me an attempt. My implementation is only 12 lines of code. Also, I think I deserve "best answer".
ChapMast... at Yahoo! Answers Visit the source
Related Q & A:
- How to skip columns empty in CSV file when importing into MySQL table using LOAD DATA INFILE?Best solution by Stack Overflow
- Can I recover lost data from an .mdf or .ldf file?Best solution by Database Administrators
- How to get difference between two dates in years, months and days?Best solution by Stack Overflow
- How to write binary data to a file?Best solution by Stack Overflow
- How to read Json Data from online file?Best solution by mkyong.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.