Question

In: Computer Science

USING THE IF STATEMENT & Scanner for input and println for output - Write a java...

  1. USING THE IF STATEMENT & Scanner for input and println for output - Write a java program where the user enters a temperature as a whole number from input, and outputs a “most likely” season [either SUMMER, SPRING, FALL or WINTER] depending on the temperature entered.

SUMMER would be 90 or higher

SPRING   would be 70 to less than 90

FALL       would be 50 to less than 70

WINTER would be less than 50

Consider it an error if the user ever accentually enters a value less than 0, greater than 110.

Solutions

Expert Solution

import java.util.Scanner;
public class Temperature
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter temperature: ");
        int temp = sc.nextInt();
      
        if(temp < 0 || temp > 110)
            System.out.println("Please enter a valid temperature value");
      
        else if(temp >= 90)
            System.out.println("Most Likely SUMMER");
          
        else if(temp >= 70 && temp < 90)
            System.out.println("Most Likely SPRING");
      
        else if(temp >= 50 && temp < 70)
            System.out.println("Most Likely FALL");
          
        else if(temp < 50)
            System.out.println("Most Likely WINTER");
    }
}


Related Solutions

Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or...
Objectives: Write a program which reads User Input using Scanner Print formatted output using printf or DecimalFormat Practice programming simple mathematical calculations Instructions: Samwise Gamgee has finally decided to submit his expense report for all of his adventures regarding his travels to Mordor. Part of those expenses are his stay at the Prancing Pony Inn located in Bree. You are to write a simple Java program which will generate an Invoice for his stay at the Inn. Your program should...
• Using the Scanner class to obtain input from the user. • Using printf to output...
• Using the Scanner class to obtain input from the user. • Using printf to output information to the user. • Using arithmetic operators to perform calculations. • Using if statements to make decisions based on the truth or falsity of a condition. • Using relational operators to compare variable values. Project 1: Write an application that asks the user to enter two integers, obtains them from the user and prints their sum, product, difference and quotient (division). Sample Output:...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner object to read input. int Age;     Write a java statement to read the Age input value 4 . Redo 1 to 3 using JOptionPane
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
In Java INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the...
In Java INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the computer user to enter his/her: • Name: a string representing the user’s first name • month of birthday: an integer representing the month of the user’s birthday • day of birthday: an integer representing the day of the user’s birthday • year of birthday: an integer representing the year of the user’s birthday Consider the following aspects that your program shall perform: VALIDATE USER’S...
Submit a java file. Write a program where you input 4 numbers and the output generates...
Submit a java file. Write a program where you input 4 numbers and the output generates the average of the 4 numbers. The output may not be negative and <= 100. If any value is negative or >100, it should be replaced by the value of 30. For all such values, you will replace them with a value of 10. The program should produce the following output: Today's average amount is: $xx.xx.
Define a java problem with user input, user output, Do While Statement and some mathematical computation....
Define a java problem with user input, user output, Do While Statement and some mathematical computation. Write the pseudocode, code and display output.
Write a program that produces the following output using nested for loop in Java. ****** ////////////...
Write a program that produces the following output using nested for loop in Java. ****** //////////// ****** ***** //////////\\ ***** **** ////////\\\\ **** *** //////\\\\\\ *** ** ////\\\\\\\\ ** * //\\\\\\\\\\ * \\\\\\\\\\\\
Write a program with total change amount as an integer input, and output the change using...
Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes c++ please
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT