Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Arrays;
- import java.util.Scanner;
- public class finalexam {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- //Declaring the arrays for month, day, year, and temperature
- int[] month = new int[9088];
- int[] day = new int[9088];
- int[] year = new int[9088];
- double[] temperature = new double[9088];
- Scanner in = null;
- //Using the Albirmin text to pull into the program to use for the arrays above
- try {
- in = new Scanner(new File("C:\\Users\\v113\\eclipse-workspace\\CS\\src\\ALBIRMIN.txt"));
- }
- catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- in.nextLine();
- int count = 0;
- //Repeating all the sections until the end of the text to be used
- while (in.hasNextInt()) {
- month[count] = in.nextInt();
- day [count] = in.nextInt();
- year [count] = in.nextInt();
- temperature [count] = in.nextDouble();
- count++;
- }
- //Using the arrays to find which values are the maximum and minimum of temperature
- Arrays.sort(temperature);
- //Finding the average temperature
- double totalTemp = 0;
- for(int i = 0; i<temperature.length; i++){
- totalTemp = totalTemp + temperature[i];
- if (temperature[i] == (91.0)) {
- int dayMax = day[i];
- int yearMax = year[i];
- int monthMax = month[i];
- }
- }
- double averageTemp = totalTemp / temperature.length;
- //Printing out all the averages, maximums, dates, and minimums
- System.out.format("Average temperature in Bramingham, Alabama is %.3f", averageTemp);
- System.out.println("");
- System.out.println("Maximum temperature in Bramingham, Alabama is " + temperature[temperature.length-1]);
- System.out.println("It happened on");
- //System.out.println(Month + " - " + Day + " - " + Year);
- System.out.println("Minimum temperature in Bramingham, Alabama is " + temperature[0]);
- System.out.println("It happened on");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement