Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class WeatherArray {
  7.  
  8. public static void main(String[] args)
  9. throws FileNotFoundException{
  10.  
  11. Scanner input = new Scanner(new File("PortlandWeather2011.txt"));
  12.  
  13. String head = input.nextLine();
  14. String head2 = input.nextLine();
  15. System.out.println(head);
  16. System.out.println(head2);
  17.  
  18. int count = 0;
  19. while(input.hasNextLine()){
  20. process(input);
  21. count++;
  22. }
  23.  
  24. double[] prcp = new double[count];
  25. double[] snow = new double[count];
  26. double[] snwd = new double[count];
  27. double[] tmin = new double[count];
  28. double[] tmax = new double[count];
  29.  
  30. input = new Scanner(new File("PortlandWeather2011.txt"));
  31.  
  32. head = input.nextLine();
  33. head2 = input.nextLine();
  34. System.out.println(head);
  35. System.out.println(head2);
  36.  
  37. count = 0;
  38. while(input.hasNextLine()){
  39. input.next();
  40. input.next();
  41. prcp[count] = input.nextDouble();
  42. snow[count] = input.nextDouble();
  43. snwd[count] = input.nextDouble();
  44. tmin[count] = input.nextDouble();
  45. tmax[count] = input.nextDouble();
  46. count++;
  47. }
  48. System.out.println(arrayAvg(prcp));
  49. System.out.println(arrayAvg(snow));
  50. System.out.println(arrayAvg(snwd));
  51. System.out.println(arrayAvg(tmin));
  52. System.out.println(arrayAvg(tmax));
  53. }
  54. public static void process(Scanner input){
  55. while(input.hasNext()){
  56. String station = input.next();
  57.  
  58. while(input.hasNextInt()){
  59. String date = input.next();
  60.  
  61. while(input.hasNextInt()){
  62. int prcp = input.nextInt();
  63.  
  64. while(input.hasNextInt()){
  65. int snow = input.nextInt();
  66.  
  67. while(input.hasNextInt()){
  68. int snwd = input.nextInt();
  69.  
  70. while(input.hasNextInt()){
  71. int tmin = input.nextInt();
  72.  
  73. while(input.hasNextInt()){
  74. int tmax = input.nextInt();
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. public static double arrayAvg(double array[]){
  84. int count = 0;
  85. double sum = 0;
  86. for(int i = 0; i < array.length; i++){
  87. count++;
  88. if(array[i] != 393.7){
  89. sum += array[i];
  90. }
  91. }
  92. return sum/count;
  93. }
  94.  
  95. }
  96.  
  97. public class MaainActivity extends Activity {
  98.  
  99. @Override
  100. public void onCreate(Bundle savedInstanceState) {
  101. super.onCreate(savedInstanceState);
  102. // Get the view from activity_main.xml
  103. setContentView(R.layout.activity_main);
  104.  
  105. }
  106. }
  107.  
  108. public class MainActivity extends Activity {
  109.  
  110.  
  111. @Override
  112. public void onCreate(Bundle savedInstanceState) {
  113. super.onCreate(savedInstanceState);
  114. // Get the view from activity_main.xml
  115. setContentView(R.layout.activity_main);
  116.  
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement