Computers and Technology

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");

} }
}

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:00, AshlynPlayz45
Which one of the following would administrators use to connect to a remote server securely for administration? a. telnetb. secure file transfer protocol (sftp)c. secure copy (scp)d. secure shell (ssh)
Answers: 1
image
Computers and Technology, 22.06.2019 03:30, samone26
Some of your friends have gotten into the burgeoning field of time-series data mining, in which one looks for patterns in sequences of events that occur over time. purchases at stock exchanges--what’s being bought-- are one source of data with a natural ordering in time. given a long sequence s of such events, your friends want an efficient way to detect certain "patterns" in them--for example, they may want to know if the four events buy yahoo, buy ebay, buy yahoo, buy oracle occur in this sequence s, in order but not necessarily consecutively. they begin with a collection of possible events (e. g., the possible’ transactions) and a sequence s of n of these events. a given event may occur multiple times in s (e. g., yahoo stock may be bought many times in a single sequence s). we will say that a sequence s’ is a subsequence of s if there is a way to delete certain of the events from s so that the remaining events, in order, are equal to the sequence s’. so, for example, the sequence of four events above is a subsequence of the sequence buy amazon, buy yahoo, buy ebay, buy yahoo, buy yahoo, buy oracle their goal is to be able to dream up short sequences and quickly detect whether they are subsequences of s. so this is the problem they pose to you: give an algorithm that takes two sequences of even~s--s’ of length m and s of length n, each possibly containing an event more than once--and decides in time o(m n) whether s’ is a subsequence of s
Answers: 2
image
Computers and Technology, 23.06.2019 11:00, shawn20034
This chapter lists many ways in which becoming computer literate is beneficial. think about what your life will be like once you’re started in your career. what areas of computing will be most important for you to understand? how would an understanding of computer hardware and software you in working from home, working with groups in other countries and contributing your talents.
Answers: 1
image
Computers and Technology, 23.06.2019 13:30, jhitotw
What is the primary difference between the header section of a document and the body? a. the body is displayed on the webpage and the header is not. b. the header is displayed on the webpage and the body is not. c. the tag for the body is self-closing, but the tags for the headers must be closed. d. the tag for the header is self closing, but the tag for the body must be closed.
Answers: 3
Do you know the correct answer?
Write a program that takes a date as input and outputs the date's season. The input is a string to r...

Questions in other subjects:

Konu
Mathematics, 11.10.2020 14:01
Konu
Social Studies, 11.10.2020 14:01
Konu
Chemistry, 11.10.2020 14:01