00:01
Hello student, here's a java program named dailytemp that continuously prompt the user for the daily high temperature until they enter a sentinel value which is 999.
00:13
It also validates the input and calculates the total and average temperature.
00:18
So in this program, we are using a while loop to continuously prompt the user for the temperature until they enter the sentinel value.
00:25
We validate each input temperature using isvalidtemperature method which checks if the temperature is within the range of minus 20 to 130 which is given to us.
00:37
If the user enters a valid temperature, it is added to the total and we increment the count to keep track of the number of the valid temperature.
00:45
If the user enters an invalid temperature, it is added to the total and we increment the count to keep track of the number of the valid temperature.
01:00
So here if the user enters invalid, then the message is displayed.
01:05
After the user enters 999, the loop terminates and we calculate the display the average temperature.
01:12
So if at least one valid temperature was encountered, the program closes the scanner input before exit.
01:21
So the program ensure that the only valid temperature are considered in the average calculation and handles the invalid input gracefully.
01:30
So here name of the class is dailytemperature.
01:33
Here public static void main is taken.
01:37
Scanner class is taken.
01:38
Here temperature variable is declared.
01:41
Total is initialized to zero.
01:43
Count is initialized to zero.
01:45
After this system .out .println, enter the daily high temperature.
01:51
So here temperature must be within this range or 999 which is sentinel value which we are using for the exit.
01:59
So this sentinel value we are using for the exit.
02:02
So while true system .out .println, so here enter the temperature.
02:08
Temperature has been entered and taken as a temperature variable stored in a temperature variable.
02:14
If temperature is equal to 999, then break because from this point we have to exit.
02:21
So if now temperature validity we are checking...