In: Computer Science
IN JAVA
Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:
Day: (variable)
High: (variable)
Count High: (variable)
Total High: (variable)
Average High: (variable)
After the seven days and highs have been entered and displayed, use a For Loop to prompt the user for the days and the low temperatures. Inside the For Loop, the program will count, total, and average the lows. The following will be displayed:
Day: (variable)
Low: (variable)
Count Low: (variable)
Total Low: (variable)
Average Low: (variable)
Use a Do-While Loop to prompt the user to input the days, highs and lows. The program will count, total, and average the highs, and count, total, and average the lows. Display the following:
Day: (variable)
High: (variable)
Count High: (variable)
Total High: (variable)
Average High: (variable)
Day: (variable)
Low: (variable)
Count Low: (variable)
Total Low: (variable)
Average Low: (variable)
Prompt the user if they want to continue with another entry. If “Yes”, the DO-While repeats. If “No”, the program will end.
import java.util.*;
public class Main{
public static void main(String []args){
int i=0,High,Count_High=0,Total_High=0,Average_High=0,low,Count_low=99,Total_low=0,Average_low=0;
String Day,flag;
Scanner sc = new Scanner(System.in);
while(i<7)
{
System.out.println("Enter day"+i);
Day = sc.next();
System.out.println("Enter Highest temp of day"+i);
High = sc.nextInt();
if(High>Count_High)
Count_High=High;
Total_High+=High;
i++;
}
Average_High=Total_High/7;
System.out.println(Count_High+" "+Total_High+" "+Average_High);
for(i=0;i<7;i++)
{
System.out.println("Enter day"+i);
Day = sc.next();
System.out.println("Enter low temp of day"+i);
low = sc.nextInt();
if(low<Count_low)
Count_low=low;
Total_low+=low;
}
Average_low=Total_low/7;
System.out.println(Count_low+" "+Total_low+" "+Average_low);
do{
System.out.println("Do you want to play");
flag = sc.next();
if(flag =="No")
break;
else
{
System.out.println("Enter day"+i);
Day = sc.next();
System.out.println("Enter Highest temp of day"+i);
High = sc.nextInt();
if(High>Count_High)
Count_High=High;
Total_High+=High;
System.out.println("Enter day"+i);
Day = sc.next();
System.out.println("Enter low temp of day"+i);
low = sc.nextInt();
if(low<Count_low)
Count_low=low;
Total_low+=low;
i++;
}
}while(i<7);
Average_High=Total_High/7;
System.out.println(Count_High+" "+Total_High+" "+Average_High);
Average_low=Total_low/7;
System.out.println(Count_low+" "+Total_low+" "+Average_low);
}
}