Ask Question
24 September, 14:24

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: June 21 - September 21 Autumn: September 22 - December 20 Winter: December 21 - March 19

+4
Answers (1)
  1. 24 September, 16:25
    0
    import java. util. Scanner;

    public class LabProgram {

    public static void main (String[] args) {

    Scanner sc = new Scanner (System. in);

    String inputMonth = sc. next ();

    int inputDay = sc. nextInt ();

    if (inputMonth. equals ("January") && inputDay > = 1 && inputDay < = 31)

    System. out. println ("winter");

    else if (inputMonth. equals ("February") && inputDay > = 1 && inputDay < = 29)

    System. out. println ("winter");

    else if (inputMonth. equals ("April") && inputDay > = 1 && inputDay < = 30)

    System. out. println ("spring");

    else if (inputMonth. equals ("May") && inputDay > = 1 && inputDay < = 30)

    System. out. println ("spring");

    else if (inputMonth. equals ("July") && inputDay > = 1 && inputDay < = 31)

    System. out. println ("summer");

    else if (inputMonth. equals ("August") && inputDay > = 1 && inputDay < = 31)

    System. out. println ("summer");

    else if (inputMonth. equals ("October") && inputDay > = 1 && inputDay < = 31)

    System. out. println ("autumn");

    else if (inputMonth. equals ("November") && inputDay > = 1 && inputDay < = 30)

    System. out. println ("autumn");

    else if (inputMonth. equals ("March") && inputDay > = 20 && inputDay < = 31)

    System. out. println ("spring");

    else if (inputMonth. equals ("June") && inputDay > = 1 && inputDay < = 20)

    System. out. println ("spring");

    else if (inputMonth. equals ("June") && inputDay > = 21 && inputDay < = 30)

    System. out. println ("summer");

    else if (inputMonth. equals ("September") && inputDay > = 1 && inputDay < = 21)

    System. out. println ("summer");

    else if (inputMonth. equals ("September") && inputDay > = 22 && inputDay < = 30)

    System. out. println ("autumn");

    else if (inputMonth. equals ("December") && inputDay > = 0 && inputDay < = 20)

    System. out. println ("autumn");

    else if (inputMonth. equals ("December") && inputDay > = 21 && inputDay < = 30)

    System. out. println ("winter");

    else if (inputMonth. equals ("March") && inputDay > = 1 && inputDay < = 19)

    System. out. println ("winter");

    else

    System. out. println ("invalid");

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “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 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers