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
You have already learned about the various types of lenses. Now, conduct online research and mention as many possible types of l
Alika [10]

Answer:

nature and landscape photography: wide and ultra wide lens

wildlife photography: telephoto lens.

architectural and interior photography: wide, ultra-wide, tilt-shift lenses,

product photography: macro lenses, prime lenses, medium telephoto lenses (Up to 150mm)

insect photography: macro lenses

portrait photography: prime lenses, wide angle lens, medium telephoto lenses

wedding photography: wide-angle lenses, prime lenses

journalistic photography: wide, ultra-wide , telephoto lenses

sports photography: telephoto lenses

jewelry photography: macro lenses

Explanation:

5 0
3 years ago
Which operation is not efficiently supported by heaps?
vodka [1.7K]

In the case above, the operation is not efficiently supported by heaps is Find.

<h3>What are heap operations?</h3>

The operation that are known to often use heaps are:

  • Heapify
  • Find-max (or Find-min)
  • Insertion, etc.

Therefore, In the case above, the operation is not efficiently supported by heaps is Find.

See full question below

Which operation is not efficiently supported by heaps?

a. DeleteMin

b. Find

c. FindMin

d. Insert

e. all of the above are sufficiently supported

Learn more about operation from

brainly.com/question/24214198

#SPJ11

6 0
2 years ago
The negotiators past relationship will affect current behavior if the parties
denis-greek [22]

A. if they have been previously competetive

6 0
3 years ago
What type of firestopping technology expands as much as 25 times in volume?
love history [14]
The answer is Intumescent. I am pretty sure this is right.
7 0
3 years ago
Giving 5 stars, a Thanks, 80 points, and Branliest to whoever answers them correctly.
Mrac [35]

Answer:

Explanation:

The answer is ludonarrative.

Please mark me brainliest.

4 0
3 years ago
Other questions:
  • Mention 3 wast water draining system on home​
    7·1 answer
  • How has science fiction influenced technology
    7·2 answers
  • Design and implement an application that reads a sequence of up to 25 pairs of names and postal (ZIP) codes for individuals. Sto
    9·1 answer
  • ​User documentation _____. Group of answer choices ​allows users to prepare overall documentation, such as process descriptions
    9·1 answer
  • A store owner keeps a record of daily transactions in a text file. Each line contains three items: The invoice number, the cash
    7·1 answer
  • Assume that an array named salarySteps whose elements are of type int and that has exactly five elements has already been declar
    12·1 answer
  • How many passes will it take to find the five in this list?
    14·2 answers
  • What might a designer need to consider when choosing an appropriate energy source for products and power systems
    15·1 answer
  • James root lol ........................
    12·1 answer
  • 1) Coding for Table in Html<br>​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!