// Allison Obourn
// CS& 141, Winter 2021
// Lecture 12

// This program prompts the user for the number of temperatures  they want to input
// and then prompts them for that many temperatures. It then outputs the average
// of all the input temperatures, how many days were above average, 
// all the temperatures the user input, the two lowest temperatures input and 
// the two highest temperatures input

// NOTE: this program has too much code in main! We will talk more about how
//       to use arrays and methods together next class

import java.util.*;

public class Weather2 {
   public static void main(String[] args) {
      Scanner console = new Scanner(System.in);
      System.out.print("How many days' temperatures? ");
      int days = console.nextInt();

      int[] temps = new int[days];
      int sum = 0;
      
      // reading in all of the temperatures from the user
      for (int i = 0; i < temps.length; i++) {
         System.out.print("Day " + (i + 1) + "'s high temp: ");
         int temp = console.nextInt();
         temps[i] = temp;
         sum += temp;
      }
      
      double average = ((double) sum) / temps.length;
      
      // counting the days above average
      int aboveDays = 0;
      for(int i = 0; i < temps.length; i++) {
         if(temps[i] > average) {
            aboveDays++;
         }
      }

      System.out.printf("Average temp = %.1f\n", average);
      System.out.println(aboveDays + " days above average");
      
      System.out.println();
      System.out.println("Temperatures: " + Arrays.toString(temps));
      
      // sort the temperatures so the two lowest will be first and two highest last
      Arrays.sort(temps);
      System.out.println("Lowest temperatures: " + temps[0] + ". " + temps[1]);
      System.out.println("Highest temperatures: " + temps[temps.length - 1] + ". " 
                           + temps[temps.length - 2]);
   }
}