Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Dr Java Objective: Write a program that takes in temperatures for 10 days

ID: 3788644 • Letter: U

Question

Using Dr Java

Objective:

Write a program that takes in temperatures for 10 days and stores it in an array. Find the average temperature for those 10 days, and then print the number of days and the temperatures that were above average.

Example Dialog:

Welcome to the above average temperature tester program.

Please enter the temperature for day 1

97.0

Please enter the temperature for day 2

87.0

Please enter the temperature for day 3

85.0

Please enter the temperature for day 4

76.0

Please enter the temperature for day 5

83.0

Please enter the temperature for day 6

104.0

Please enter the temperature for day 7

78.0

Please enter the temperature for day 8

76.0

Please enter the temperature for day 9

90.0

Please enter the temperature for day 10

85.0

The average temperature was 86.1

The days that were above average were

Day 1 with 97

Day 2 with 87

Day 6 with 104

Day 9 with 90

DONE!

Explanation / Answer

TemparatureTest.java


import java.util.Scanner;

public class TemparatureTest {

  
   public static void main(String[] args) {
      
       Scanner scan = new Scanner(System.in);
       System.out.println("Welcome to the above average temperature tester program.");
       double temp[] = new double[10];
       for(int i=0; i<temp.length; i++){
           System.out.println("Please enter the temperature for day "+(i+1)+": ");
           temp[i] = scan.nextDouble();
       }
       double sumTemp = 0;
       for(int i=0; i<temp.length; i++){
           sumTemp = sumTemp + temp[i];
       }
       double averageTemp = sumTemp/temp.length;
       System.out.println("The average temperature was "+averageTemp);
       System.out.println("The days that were above average were: ");
       for(int i=0; i<temp.length; i++){
           if(averageTemp < temp[i]){
               System.out.println("Day "+(i+1)+" with "+temp[i]);
           }
       }
       System.out.println("DONE!");
   }

}

Output:

Welcome to the above average temperature tester program.
Please enter the temperature for day 1:
97.0
Please enter the temperature for day 2:
87.0
Please enter the temperature for day 3:
85.0
Please enter the temperature for day 4:
76.0
Please enter the temperature for day 5:
83.0
Please enter the temperature for day 6:
104.0
Please enter the temperature for day 7:
78.0
Please enter the temperature for day 8:
76.0
Please enter the temperature for day 9:
90.0
Please enter the temperature for day 10:
85.0
The average temperature was 86.1
The days that were above average were:
Day 1 with 97.0
Day 2 with 87.0
Day 6 with 104.0
Day 9 with 90.0
DONE!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote