1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
valentinak56 [21]
3 years ago
13

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 in

t 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"&&inputDay>19)||inputMonth=="April"||inputMonth=="May"||(inputMonth=="June"&&inputDay<21))
{
System.out.println("spring");
}
else if((inputMonth=="June"&&inputDay>20)||inputMonth=="July"||inputMonth=="August"||(inputMonth=="September"&&inputDay<22))
{
System.out.println("summer");
}
else if((inputMonth=="September"&&inputDay>21)||inputMonth=="October"||inputMonth=="November"||(inputMonth=="December"&&inputDay<21))
{
System.out.println("autumn");
}
else if((inputMonth=="December"&&inputDay>20)||inputMonth=="January"||inputMonth=="February"||(inputMonth=="March"&&inputDay<20))
{
System.out.println("winter");
}
else
{
System.out.println("invalid");

} }
}

Computers and Technology
1 answer:
Ulleksa [173]3 years ago
3 0

Answer:

The problem here is you are comparing month names with == , in case of strings there is a difference between comparing with == and .equals. So I have changed that code please check now

Program:

import java.util.Scanner;

public class LabProgram {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

String inputMonth;

int inputDay;

System.out.print("Enter month:");

inputMonth = scnr.next();

System.out.print("Enter day of month");

inputDay = scnr.nextInt();

if((inputMonth.equalsIgnoreCase("march")&&inputDay>19)||inputMonth.equalsIgnoreCase("april")||inputMonth=="may"||(inputMonth.equalsIgnoreCase("june")&&inputDay<21))

{

System.out.println("spring");

}

else if((inputMonth.equalsIgnoreCase("june")&&inputDay>20)||inputMonth.equalsIgnoreCase("july")||inputMonth=="august"||(inputMonth.equalsIgnoreCase("september")&&inputDay<22))

{

System.out.println("summer");

}

else if((inputMonth.equalsIgnoreCase("september")&&inputDay>21)||inputMonth.equalsIgnoreCase("october")||inputMonth.equalsIgnoreCase("november")||(inputMonth.equalsIgnoreCase("December")&&inputDay<21))

{

System.out.println("autumn");

}

else if((inputMonth.equalsIgnoreCase("december")&&inputDay>20)||inputMonth.equalsIgnoreCase("january")||inputMonth.equalsIgnoreCase("february")||(inputMonth.equalsIgnoreCase("march")&&inputDay<20))

{

System.out.println("winter");

}

else

{

System.out.println("invalid");

} }

}

Output:

You might be interested in
What are the types of technology that is use in education and what are their usages​
hjlf
Computers and Tablets I think
5 0
3 years ago
Do you think Apple will eventually meet their goal of becoming a replacement for a physical wallet
Dmitry_Shevchenko [17]
Yes they are the leading tech innovators of the 21st century and have already made massive strides in this direction
8 0
3 years ago
in order to switch from paper to digital medical records the hospital bought in several individuals to introduce and implement t
VladimirAG [237]

Available options are:

A. Technical champions

B. Engaged filmmakers

C. Business partners

D. Compliance champions

Answer:

Technical champions

Explanation:

Given that a "Technical Champion" is someone whose responsibility is to introduce and perform the role of enabling the use of technology, development of skills across the organization, and strengthen communication between Information Technology and the staff or employees.

Hence, in this case, considering the job descriptions described in the question above, these individuals would best be described as TECHNICAL CHAMPIONS

6 0
3 years ago
Which wireless communication is typically limited to six feet of distance?
Anni [7]

Answer:

nfc

Explanation:

8 0
3 years ago
You are gong to buy a computer but first you want to do some research to help you select the best model for your needs
DerKrebs [107]

Answer:

Research what kind of computer you want.

Explanation:

I don't know exactly what you are asking here but when doing research you have got to know what you want like how much ram you want, how much storage you want, what brand of computer you want, what core processor you want, and what graphics card you want. You also have to decide if you want a laptop or a full sized desk top computer.

8 0
3 years ago
Other questions:
  • SP 800-14, Generally Accepted Principles and Practices for Securing Information Technology Systems, provides best practices and
    9·2 answers
  • What does "FDDI" stand for in Technology?
    5·2 answers
  • Service that connects on-premises software appliances with cloud based storage is ______
    10·1 answer
  • Explain what the hazard detection unit is doing during the 5th cycle of execution. Which registers are being compared? List all
    6·1 answer
  • Is the following statement TRUE or FALSE?
    9·1 answer
  • What is data Communications​
    11·2 answers
  • The purpose of​ a/an _________ system is to capture best practice solutions and program them into a set of rules in a software p
    13·1 answer
  • What makes a source credible?
    9·2 answers
  • Create a list of 5 potential jobs that students of computer science can obtain.
    9·2 answers
  • How are 1gls different from 2gls​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!