Question

2. Implement an application in Java such that if the user enters a month and a day, it should display the name of the season.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import javax.swing.*;

public class SeasonsUI {

    public static void main(String[] args) {
        String inputMonth = JOptionPane.showInputDialog("Enter month: ");
        int inputDay = Integer.parseInt(JOptionPane.showInputDialog("Enter day: "));
        String season;

        if (inputMonth.equalsIgnoreCase("January") && inputDay >= 1 && inputDay <= 31)
            season = "Winter";
        else if (inputMonth.equalsIgnoreCase("February") && inputDay >= 1 && inputDay <= 29)
            season = "Winter";
        else if (inputMonth.equalsIgnoreCase("April") && inputDay >= 1 && inputDay <= 30)
            season = "Spring";
        else if (inputMonth.equalsIgnoreCase("May") && inputDay >= 1 && inputDay <= 30)
            season = "Spring";
        else if (inputMonth.equalsIgnoreCase("July") && inputDay >= 1 && inputDay <= 31)
            season = "Summer";
        else if (inputMonth.equalsIgnoreCase("August") && inputDay >= 1 && inputDay <= 31)
            season = "Summer";
        else if (inputMonth.equalsIgnoreCase("October") && inputDay >= 1 && inputDay <= 31)
            season = "Autumn";
        else if (inputMonth.equalsIgnoreCase("November") && inputDay >= 1 && inputDay <= 30)
            season = "Autumn";
        else if (inputMonth.equalsIgnoreCase("March") && inputDay >= 20 && inputDay <= 31)
            season = "Spring";
        else if (inputMonth.equalsIgnoreCase("June") && inputDay >= 1 && inputDay <= 20)
            season = "Spring";
        else if (inputMonth.equalsIgnoreCase("June") && inputDay >= 21 && inputDay <= 30)
            season = "Summer";
        else if (inputMonth.equalsIgnoreCase("September") && inputDay >= 1 && inputDay <= 21)
            season = "Summer";
        else if (inputMonth.equalsIgnoreCase("September") && inputDay >= 22 && inputDay <= 30)
            season = "Autumn";
        else if (inputMonth.equalsIgnoreCase("December") && inputDay >= 0 && inputDay <= 20)
            season = "Autumn";
        else if (inputMonth.equalsIgnoreCase("December") && inputDay >= 21 && inputDay <= 30)
            season = "Winter";
        else if (inputMonth.equalsIgnoreCase("March") && inputDay >= 1 && inputDay <= 19)
            season = "Winter";
        else
            season = "Invalid";

        JOptionPane.showMessageDialog(null, "Season: " + season);
    }
}
Add a comment
Know the answer?
Add Answer to:
2. Implement an application in Java such that if the user enters a month and a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please show output in python Write a program that takes a date as input and outputs...

    Please show output in python Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March...

  • Write a program that takes a date as input and outputs the date's season. The input...

    Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an int to represent the day. Ex: If the input is: April 11 the output is: Spring In addition, check if the string and int are valid (an actual month and day). Ex: If the input is: Blue 65 the output is: Invalid The dates for each season are: Spring: March 20 - June 20 Summer:...

  • Use R to solve these problems 8. The year is divided into four seasons: spring, summer,...

    Use R to solve these problems 8. The year is divided into four seasons: spring, summer, fall and winter While the exact dates that the seasons change vary a little bit from year to year because of the way that the calendar is constructed, we will use the following dates for this exercise: Season rin Summer Fall Winter Start March June September December End Ma August November Februa Create a program that reads a month from the user. The user...

  • 1) Write a Python program that prompts the user to enter the current month name and...

    1) Write a Python program that prompts the user to enter the current month name and prints the season for that month. Hint: If the user enters March, the output should be "Spring"; if the user enters June, the output should be "Summer". 2 )Write a Python program using the recursive/loop structure to print out an equilateral triangle below (double spacing and one space between any two adjacent asterisks in the same row).          *      * * * *...

  • Design JavaFX application with 7 labels and one textfield where user enters input inches. When user...

    Design JavaFX application with 7 labels and one textfield where user enters input inches. When user enters his choice and presses enter key to complete input, program outputs resulting yards, feet, and inches. Use class P5 that extends Application with start method in it, and class P5Pane that extends GridPane. The only instance variables for P5Pane class are inputInches where user enters input inches, and three labels: outYards, outFeet, and outInches where program displays result of conversion. Use the following...

  • use python Write a program that asks the user for day and month of a birthday....

    use python Write a program that asks the user for day and month of a birthday. The program then tells the Zodiac signs that will be compatible with that birthday. #Example for Aries The Ram    Mar. 21–Apr. 19 day = 24 # user enters this month = 3 # user enters this if ( month == 3 and day >=21) or (month == 4 and day <= 19): print("You are Aries, Fire group, compatible with Aries, Leo, Sagittarius") Zodiac Signs:...

  • Write a java application that is including a three-question multiple choice quiz about Java programming language....

    Write a java application that is including a three-question multiple choice quiz about Java programming language. Each question must have four possible answers (numbered 1 to 4). Also, ask user to type 0 to exit the test. [Assume that a user enters only integers 1,2,3,4, or 0]. Firstly, display a message that this quiz includes three questions about the Java programming language and display that each question has four possible answers. If the answer is correct for the given question,...

  • a. Write an application for Cody's Car Care Shop that shows a user a list of...

    a. Write an application for Cody's Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as $25, $22, $15, or $5, accordingly. Display an error message if the user enters an invalid item. Save the file as CarCareChoice.java. b. It might not be reasonable to expect users...

  • Create a function that will accept a date as input and will return if this date happens in fall, spring, winter or summ...

    Create a function that will accept a date as input and will return if this date happens in fall, spring, winter or summer. Before you start writing this function experiment with queries below. Current date select sysdate from dual; Yesterday select sysdate - 1 from dual; Tomorrow select sysdate + 1 from dual; The date format element D returns the number of the day of the week (1-7). select to_char(sysdate,'D') from dual; MM returns two-digit numeric abbreviation of month (01-12;...

  • c# language Description: Design and implement a C# application that allows the user to enter a...

    c# language Description: Design and implement a C# application that allows the user to enter a number N. It returns to the user the result of the Fibonacci of N. The Fibonacci of a number N is calculated as follows: Fibonacci (0) 0 Fibonacci (1) - Fibonacci (n) - Fibonacci (n-1) + Fibonacci (n-2) Requirements Your Application should have the following: • An exception class called FibException that is thrown when the user enters a negative value of N •...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT