Calculating average weekly temperature – Java Program

What it does:

A program to find the average of weekly temperature. It will prompt the user to enter a temperature for each day of the week. Where at the end of the program it will find out there average. It will also prompt the user to see if they would like to use the program again entering different temperatures.


public class WeeklyTemperatures
   static double monTemp, tueTemp, wedTemp, thurTemp, friTemp, satTemp, sunTemp;
   static Scanner keyboard = new Scanner(;
   static DecimalFormat df = new DecimalFormat("00.00");

   public static void menu()
      System.out.println("Welcome to the temperature calculator\n");

      //Prompting user for the temperature each day
      System.out.println("Please enter Monday's temperature. ");
      monTemp = keyboard.nextDouble();

      System.out.println("Please enter Tuesday's temperature. ");
      tueTemp = keyboard.nextDouble();

      System.out.println("Please enter Wednesday's temperature. ");
      wedTemp = keyboard.nextDouble();

      System.out.println("Please enter Thursday's temperature. ");
      thurTemp = keyboard.nextDouble();

      System.out.println("Please enter Friday's temperature. ");
      friTemp = keyboard.nextDouble();

      System.out.println("Please enter Saturday's temperature. ");
      satTemp = keyboard.nextDouble();

      System.out.println("Please enter Sunday's temperature. ");
      sunTemp = keyboard.nextDouble();


   public static void dailyAverageTemp()
      int day;

      System.out.println("\nTo see the average daily temperature, please enter the number " +
              "for the day of the week you wish to view.");

      System.out.println("1. Monday");
      System.out.println("2. Tuesday");
      System.out.println("3. Wednesday");
      System.out.println("4. Thursday");
      System.out.println("5. Friday");
      System.out.println("6. Saturday");
      System.out.println("7. Sunday\n");
      day = keyboard.nextInt();

      switch (day)

         case 1: System.out.println("Monday's average temperature was "+(df.format(monTemp))+"C");
         case 2: System.out.println("Tuesday's average temperature was "+(df.format(tueTemp))+"C");
         case 3: System.out.println("Wednesday's average temperature was "+(df.format(wedTemp))+"C");
         case 4: System.out.println("Thursday's average temperature was "+(df.format(thurTemp))+"C");
         case 5: System.out.println("Friday's average temperature was "+(df.format(friTemp))+"C");
         case 6: System.out.println("Saturday's average temperature was "+(df.format(satTemp))+"C");
         case 7: System.out.println("Sunday's average temperature was "+(df.format(sunTemp))+"C");



   public static void calculatingAverageWeeklyTemp()
      double sumOfTemps;
      double averageWeeklyTemp;

      //Adding all the temperatures for each day together.
      sumOfTemps = monTemp+tueTemp+wedTemp+thurTemp+friTemp+satTemp+sunTemp;

      //Dividing the sum of all temperatures by 7 to find the average weekly temp.
      averageWeeklyTemp = sumOfTemps/7;

      System.out.println("\nThe average weekly temperature was "+(df.format(averageWeeklyTemp))+"C");


   public static void exit()

      int choice;

      System.out.println("\nWould you like to exit?");
      System.out.println("1. Yes");
      System.out.println("2. No");
      choice = keyboard.nextInt();

      if(choice ==1)
         System.out.println("\nThank-you for using this system!");

         System.out.println("\nYou will now be redirected to the main menu");


   public static void main(String[] args)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s