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 message did vera mukhina convey in her work entitled the worker and the collective farmworker?
Dominik [7]

Answer:

She glorified the communal labor of the Soviet people

3 0
1 year ago
A highly available server is available what percentage of the time?
Verdich [7]

Answer:

b. 99.99%

Explanation:

<u>High available server</u>

A typical dedicated server is a strong machine linked to a high-speed Internet connection and located in a state-of - the-art distant data center or optimized information warehouse.

A dedicated High Availability Server is an sophisticated system with redundant network,redundant power supplies and backups to ensure maximum up-time.

5 0
3 years ago
Which of the following manages allocation of computer resources during program execution?
Brums [2.3K]
A)memory management
8 0
4 years ago
What is copy formatting​
liraira [26]

Answer:

Copy formatting lets you copy all the formatting from one object and apply it to another one, think of it as copying and pasting formatting.

6 0
3 years ago
Match the OOP concept to its definition.
Alekssandra [29.7K]

Answer:

defines a class in terms of another class = inheritance

inherits the properties of a base class = derived class

provides only essential information to the world = data abstraction

binds data and functions together = encapsulation

Explanation:

6 0
3 years ago
Other questions:
  • How do u change the level of education on Brainly. cuz i just finished elementry
    9·2 answers
  • The smallest unit of storage in the following list is a
    7·1 answer
  • The ____ layer protocols are the rules for implementing end-user services provided by a network. Transport Application Physical
    11·1 answer
  • While using a word processor to create a project report, Ashley includes the subject, title, and the author's name in the report
    7·1 answer
  • A ________ refers to specific content of a field.
    7·1 answer
  • Which of the following statements is true of algorithms?
    15·1 answer
  • The long-run average cost curve is typically _______________________. a) downward-sloping at first but then b) upward-sloping up
    14·1 answer
  • What is it important to test cabless?​
    7·1 answer
  • Explain with examples: <br> What are the reasons of a successful and unsuccessful software project?
    14·1 answer
  • What are the different Stape of data processing cycle?​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!