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 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.
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...
Problem 4 : Write a program that prompts the user to enter in an integer and...
Problem 4 : Write a program that prompts the user to enter in an integer and then prints as shown in the example below Enter an integer 5 // User enters 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Bye
IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
Part A In PyCharm, write a program that prompts the user for their name and age....
Part A In PyCharm, write a program that prompts the user for their name and age. Your program should then tell the user the year they were born. Here is a sample execution of the program with the user input in bold: What is your name? Amanda How old are you? 15 Hello Amanda! You were born in 2005. Write the program. Format your code using best practices. Refer to the zyBooks style guide, if needed, to use proper naming...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT