Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class finalexam {
  7.  
  8. public static void main(String[] args) {
  9. // TODO Auto-generated method stub
  10.  
  11. //Declaring the arrays for month, day, year, and temperature
  12. int[] month = new int[9088];
  13. int[] day = new int[9088];
  14. int[] year = new int[9088];
  15. double[] temperature = new double[9088];
  16. Scanner in = null;
  17.  
  18. //Using the Albirmin text to pull into the program to use for the arrays above
  19. try {
  20. in = new Scanner(new File("C:\\Users\\v113\\eclipse-workspace\\CS\\src\\ALBIRMIN.txt"));
  21. }
  22. catch (FileNotFoundException e) {
  23. e.printStackTrace();
  24. }
  25.  
  26. in.nextLine();
  27.  
  28. int count = 0;
  29.  
  30. //Repeating all the sections until the end of the text to be used
  31. while (in.hasNextInt()) {
  32. month[count] = in.nextInt();
  33. day [count] = in.nextInt();
  34. year [count] = in.nextInt();
  35. temperature [count] = in.nextDouble();
  36. count++;
  37. }
  38.  
  39.  
  40.  
  41.  
  42. //Finding the average temperature
  43. double totalTemp = 0;
  44.  
  45.  
  46. for(int i = 0; i<temperature.length; i++){
  47. totalTemp = totalTemp + temperature[i];
  48.  
  49. if (temperature[i] == 91.0) {
  50. System.out.println("It happened on");
  51. System.out.println(month[i] + " - " + day[i] + " - " + year[i]);
  52. }
  53.  
  54.  
  55. }
  56.  
  57.  
  58. Arrays.sort(temperature);
  59.  
  60.  
  61.  
  62. double averageTemp = totalTemp / temperature.length;
  63.  
  64. //Printing out all the averages, maximums, dates, and minimums
  65. System.out.format("Average temperature in Bramingham, Alabama is %.3f", averageTemp);
  66. System.out.println("");
  67. System.out.println("Maximum temperature in Bramingham, Alabama is " + temperature[temperature.length-1]);
  68. System.out.println("It happened on");
  69. System.out.println("Minimum temperature in Bramingham, Alabama is " + temperature[0]);
  70. System.out.println("It happened on");
  71. }
  72.  
  73.  
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement