subject

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 invalid, 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

My code is constantly outputting 'invalid, regardless of the date input.

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=="March"&&in putDay>19)||inputMonth=="April"| |inputMonth=="May"||(inputMonth=="J une"&&inputDay<21))
{
System. out. println("spring");
}
else if((inputMonth=="June"&&inp utDay>20)||inputMonth=="July"||i nputMonth=="August"||(inputMonth==" September"&&inputDay<22) )
{
System. out. println("summer");
}
else if((inputMonth=="September"&&am p;inputDay>21)||inputMonth=="Oct ober"||inputMonth=="November"||(inp utMonth=="December"&&inputD ay<21))
{
System. out. println("autumn");
}
else if((inputMonth=="December"&& ;inputDay>20)||inputMonth=="Janu ary"||inputMonth=="February"||(inpu tMonth=="March"&&inputDay&l t;20))
{
System. out. println("winter");
}
else
{
System. out. println("invalid");

} }
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 03:30
Which explains extrinsic motivation? a)motivation in which there is a reward b)motivation that is personally satisfying c)motivation that is personally meaningful d)motivation in which the subject is interesting
Answers: 1
question
Computers and Technology, 24.06.2019 18:50
Write a program that reads in a series of lines of input character by character (using the library function the first line of the input contains an integer which specifies the number of remaining lines of input, each of which contains a floating point number. the integer value on the first line can be read with (the library function) but all of the following lines can only be read with each line, after the first, contains a single floating point value, with up to four digits before the decimal point, and up to four digits following the decimal point, but there is not necessarily a decimal point in each number; i.e., it may appear to be an integer, but the digits should be read by your program, and the number should be converted to a corresponding floating point number. for instance, suppose the following input: 5 3.1255 20.25 0.875 1921.50 31 the required output is: − each of the input floating point values, printed on a separate line with four digits of precision, using printf(); − on the last line of the output, the string “total: ” followed by the sum of the input values, printed with printf() to 4 digits of precision. for example, the total of the sample input given above is 1976.7505, so the required output for this input would be: 3.1255 20.2500 0.8750 1921.5000 31.0000 total: 1976.7505 do not concern yourself with small differences in the total due to rounding, as the grader will not deduct points for this. constraints: − you are not allowed to use arrays on this portion of the lab assignment. − there is no maximum number of lines allowable. it all depends upon the first value of input. since you aren’t saving anything, it doesn’t matter. − you can assume that input will not contain more than 4 digits before or after the decimal point. you do not need to error check for this condition. -you must use getchar() to read in the floating point values one character at a time (i.e. do not use -you must declare and use your floating point values as a double to minimize rounding errors. -only use printf() to output the floating point numbers and the total (do not use − be sure your directions to the user are clear so they are sure to enter the input data correctly.
Answers: 1
question
Computers and Technology, 24.06.2019 23:30
What is the opening page of a website called? a. web page b. landing page c. homepage d. opening page
Answers: 1
question
Computers and Technology, 25.06.2019 07:10
When you “listen” to evaluate an online message, which question should you ask?
Answers: 1
You know the right answer?
Write a program that takes a date as input and outputs the date's season. The input is a string to r...
Questions
question
Mathematics, 24.06.2020 02:01
Questions on the website: 13722360