In: Computer Science
Create a program that when run, prompts the user to enter a city name, a date, the minimum temperature and the maximum temperature.
Calculate the difference between the maximum temperature and the minimum temperature. Calculate the average temperature based on the minimum and maximum temperature. Print out the following:
The following is a sample run, user input is shown in bold underline.
Enter City Name: Palm Desert
Enter Date: Feb 4, 2020
Min temp: 3
Max temp: 18
Temperature statistics for Palm Desert
For: Feb 4, 2020
Min: 3.0
Max: 18.0
Difference: 15.0
Average: 10.5
please answer in java language
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
//importing required package
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
//Scanner is used to take inputs from the user
Scanner scnr = new Scanner(System.in);
System.out.print("Enter City Name:
");
//getting City Name as user input
from the user
String city =
scnr.nextLine();
System.out.print("Enter Date:
");
//getting Date as user input from
the user
String date =
scnr.nextLine();
System.out.print("Min temp:
");
//getting Minimum Temperature as
user input from the user
Float min = scnr.nextFloat();
System.out.print("Max temp:
");
//getting Maximum Temperature as
user input from the user
Float max = scnr.nextFloat();
System.out.println();
//printing city, date, min temp,
max temp, Difference, Average
System.out.println("Temperature
statistics for "+city);
System.out.println("For:
"+date);
System.out.println("Min:
"+min);
System.out.println("Max:
"+max);
// Difference = Max temp - Min
temp
System.out.println("Difference:
"+(max-min));
//Average = (Max temp + Min
temp)/2
System.out.println("Average:
"+((max+min)/2));
}
}
//code ended here
Output:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!