Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 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. //Using the arrays to find which values are the maximum and minimum of temperature
  40. Arrays.sort(temperature);
  41.  
  42. //Finding the average temperature
  43. double totalTemp = 0;
  44.  
  45. for(int i = 0; i<temperature.length; i++){
  46. totalTemp = totalTemp + temperature[i];
  47.  
  48. if (temperature[i] == (91.0)) {
  49. int dayMax = day[i];
  50. int yearMax = year[i];
  51. int monthMax = month[i];
  52.  
  53. }
  54.  
  55.  
  56. }
  57.  
  58.  
  59. double averageTemp = totalTemp / temperature.length;
  60.  
  61. //Printing out all the averages, maximums, dates, and minimums
  62. System.out.format("Average temperature in Bramingham, Alabama is %.3f", averageTemp);
  63. System.out.println("");
  64. System.out.println("Maximum temperature in Bramingham, Alabama is " + temperature[temperature.length-1]);
  65. System.out.println("It happened on");
  66. //System.out.println(Month + " - " + Day + " - " + Year);
  67. System.out.println("Minimum temperature in Bramingham, Alabama is " + temperature[0]);
  68. System.out.println("It happened on");
  69.  
  70.  
  71.  
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement