Question

In: Computer Science

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

import java.util.Scanner;

public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String inputMonth;
int inputDay;
  
/* Type your code here. */
}
}

Solutions

Expert Solution

import java.util.Scanner;

public class LabProgram {

    public static void main(String[] args) {
        Scanner scnr = new Scanner(System.in);
        String inputMonth;
        int inputDay;

        inputMonth = scnr.next();
        inputDay = scnr.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");
    }
}


Related Solutions

Write a program in python that takes a date as input and outputs the date's season....
Write a program in python 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...
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
Write a program that takes in a line of text as input, and outputs that line...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH IN C++ PLEASE!
C++ Write a program that takes a string and integer as input, and outputs a sentence...
C++ Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is "quit". If the input is: apples 5 shoes 2 quit 0 the output is: Eating 5 apples a day keeps your doctor away. Eating 2 shoes a day keeps your doctor away.
Write a program that takes a string input from the user and then outputs the first...
Write a program that takes a string input from the user and then outputs the first character, then the first two, then the first three, etc until it prints the entire word. After going up to the full word, go back down to a single letter. LastNameUpDown. Input: Kean Output: K Ke Kea Kean Kea Ke K
Write a program that takes, as input, five numbers and outputs the mean (average) and standard...
Write a program that takes, as input, five numbers and outputs the mean (average) and standard deviation of the numbers. If the numbers are x₁, x₂, x₃, x₄, and x₅, then the mean is: x = (x₁+ x₂+ x₃+ x₄+x₅)/5 and the standard deviation is: s = √(((x₁-x)²+(x₂-x)²+(x₃-x)²+(x₄-x)²+(x₅-x)²)/5) Your program must contain at least the following functions: a function that calculates and returns the mean and a function that calculates the standard deviation. Format your output with setprecision(2) to ensure...
Write a program that takes its input from a file of number type double and outputs...
Write a program that takes its input from a file of number type double and outputs the average of the numbers in the file to the screen. The file contains nothing but numbers of the type double separated by blanks and/ or line breaks. If this is being done as a class assignment, obtain the file name from your instructor. File name: pr01hw05input.txt 78.0 87.5 98.1 101.0 4.3 17.2 78.0 14.5 29.6 10.2 14.2 60.7 78.3 89.3 29.1 102.3 54.1...
Write a recursive ARM Assembly program that takes two integers as input and outputs the greatest...
Write a recursive ARM Assembly program that takes two integers as input and outputs the greatest common divisor. *I am using Eclipse DS-5 Community Workspace with A64 Instruction Set) Use the following algorithm: // Given two integers m and n: if (m < n) gcd(n, m) if n is a divisor of m gcd(m, n) = n else gcd (m, n) = gcd (n, m % n) Your program must be recursive. You must create a function that calls itself,...
In Java please: 5.23 LAB: Seasons Write a program that takes a date as input and...
In Java please: 5.23 LAB: Seasons 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:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT