Question

In: Computer Science

Create a program that when run, prompts the user to enter a city name, a date,...

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:

  • City name
  • today's Date
  • minimum temperature
  • maximum temperature
  • average temperature
  • difference between minimum and maximum

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

Solutions

Expert Solution

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!


Related Solutions

Write a program that prompts the user to enter a person’s date of birth in numeric...
Write a program that prompts the user to enter a person’s date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Follow similar conventions for the invalid values of month and year. (Note that your program...
Write a JAVA program that prompts the user to enter a single name. Use a for...
Write a JAVA program that prompts the user to enter a single name. Use a for loop to determine if the name entered by the user contains at least 1 uppercase and 3 lowercase letters. If the name meets this policy, output that the name has been accepted. Otherwise, output that the name is invalid.
Write a program that prompts the user to enter a file name, then opens the file...
Write a program that prompts the user to enter a file name, then opens the file in text mode and reads names. The file contains one name on each line. The program then compares each name with the name that is at the end of the file in a symmetrical position. For example if the file contains 10 names, the name #1 is compared with name #10, name #2 is compared with name #9, and so on. If you find...
First, the Python program prompts user to enter user information (name, email, and phone number). Then...
First, the Python program prompts user to enter user information (name, email, and phone number). Then it displays a menu called “Fish Information” that has the following fish type: 1. Cat Fish 2. Red Fish 3. Any other fish Let user choose the fish type that he/she got and input the length of the fish. Then the program will determine what should be done with this particular fish. Based on the following criteria: Criteria: Length: FISHTYPE - Cat Fish <10:...
Using C# Design and implement a program (name it CheckPoint) that prompts the user to enter...
Using C# Design and implement a program (name it CheckPoint) that prompts the user to enter the x-coordinate then y-coordinate of a point (in a Cartesian plane) as integer values. The program prints out the entered values followed by the location of the point on the plane. The possibilities for a point are: the origin point, on the x-axis, on the y-axis, in the first quadrant, in the second quadrant, in the third quadrant, or in the fourth quadrant. Format...
Use c# Create a program called ResortPrices that prompts the user to enter the number of...
Use c# Create a program called ResortPrices that prompts the user to enter the number of days for a resort stay. Then display the price per night and the total price. Nightly rates are R 500.00 for one or two nights, R 650.00 for three or four nights, R 850.00 for five, six or seven nights, and R 1500.00 for eight nights or more.
how to create s recursive function, explore that prompts the user to enter a directory name...
how to create s recursive function, explore that prompts the user to enter a directory name and an executable name, and checks that they are both readable and executable (terminating with an error message if not). It then passes the two names to the explore function. this is a part of bash scripting.
jgrasp environment, java write a complete program that prompts the user to enter their first name,...
jgrasp environment, java write a complete program that prompts the user to enter their first name, middle name, and last name (separately). print out thier name and initials, exactly as shown: your name is: John Paul Chavez your initials are: J. P. C. use string method chartAt() to extract the first (zero-th) character from a name(the name is a string type): username.charAt(0). thank you.
( USE C++ ) The program prompts the user to enter a word. The program then...
( USE C++ ) The program prompts the user to enter a word. The program then prints out the word with letters in backward order. For example, if the user enter "hello" then the program would print "olleh" show that it works .
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT