fork download
  1. import java.io.*;
  2. import java.util.*;
  3. import java.awt.*;
  4.  
  5. public class weather {
  6.  
  7. public static void main(String[] args)
  8.  
  9.  
  10. Scanner input = new Scanner(new File("PortlandWeather2011.txt"));
  11.  
  12. String x = input.nextLine();
  13. System.out.println(x);
  14. String y = input.nextLine();
  15. System.out.println(y);
  16.  
  17. int count = 0;
  18. while (input.hasNextLine()) {
  19.  
  20. process(input);
  21. count++;
  22.  
  23. }
  24.  
  25. double[] precip = new double[count];
  26. double[] snow = new double[count];
  27. double[] snowDepth = new double[count];
  28. double[] tempMin = new double[count];
  29. double[] tempMax = new double[count];
  30.  
  31. input = new Scanner(new File("PortlandWeather2011.txt"));
  32.  
  33. x = input.nextLine();
  34. System.out.println(x);
  35. y = input.nextLine();
  36. System.out.println(y);
  37.  
  38. count = 0;
  39. while (input.hasNextLine()) {
  40. input.next();
  41. input.next();
  42. precip[count] = input.nextDouble();
  43. snow[count] = input.nextDouble();
  44. snowDepth[count] = input.nextDouble();
  45. tempMax[count] = input.nextDouble();
  46. tempMin[count] = input.nextDouble();
  47. count++;
  48. }
  49.  
  50. System.out.println(arrayAvg(precip));
  51. System.out.println(arrayAvg(snow));
  52. System.out.println(arrayAvg(snowDepth));
  53. System.out.println(arrayAvg(tempMin));
  54. System.out.println(arrayAvg(tempMax));
  55. }
  56.  
  57. public static double arrayAvg(double a[]) {
  58. int count = 0;
  59. double sum = 0;
  60. for (int i = 0; i < a.length; i++) {
  61. count++;
  62. if (a[i] != 393.7) {
  63. sum += a[i];
  64.  
  65.  
  66. }
  67.  
  68. }
  69. return sum/count;
  70. }
  71.  
  72. public static void process(Scanner input) {
  73. while (input.hasNext()) {
  74. String station = input.next();
  75.  
  76. while (input.hasNextInt()) {
  77. String date = input.next();
  78.  
  79. while (input.hasNextInt()) {
  80. int precipitation = input.nextInt();
  81.  
  82. while (input.hasNextInt()) {
  83. int snow = input.nextInt();
  84.  
  85. while (input.hasNextInt()) {
  86. int snowDepth = input.nextInt();
  87.  
  88. while (input.hasNextInt()) {
  89. int tempMin = input.nextInt();
  90.  
  91. while (input.hasNextInt()) {
  92. int tempMax = input.nextInt();
  93.  
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }
  102.  
  103. public static double tempConvert(int n) {
  104. double celsius = (n / 10.0) * 9 / 5 + 32;
  105.  
  106. return celsius;
  107. }
  108.  
  109. public static double snowConvert(int n) {
  110. double snowInches = n * 0.03937;
  111.  
  112. return snowInches;
  113. }
  114.  
  115. public static double precipitationConvert(int n) {
  116. double rainInches = ((n * 0.03937) / 10);
  117. return rainInches;
  118. }
  119.  
  120. }
  121.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: class weather is public, should be declared in a file named weather.java
public class weather {
       ^
1 error
stdout

Standard output is empty