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
Which of the following is true of information systems?
timama [110]

Answer:B)They can be adapted to fit business needs.

Explanation: Information system is a system that supports the information and communication(ICT).It basically works as the interaction layer between the technology and the users an thus can flexibly work in the business field. It organizes the They are present in the many different structures such as pyramid structured information system, management information system etc.

Therefore the correct option is option(b).

4 0
3 years ago
Properly defined the primary part of a CPU​
zloy xaker [14]

Answer:

The CPU dye or the tiny resistors

Explanation:

fdsafdjslakjfdkslajfdklsajfkldsajfkldsajfkldsajfklsdajfkldsajfkldsaklfdsjal

8 0
3 years ago
How does this app work?
Natali5045456 [20]
Answer questions (don’t put random things because you can get reported and possibly suspended) to get points.

The points are needed to ask questions.

If a question helped you, you can rate it or give a thanks (click the ❤️)

For the questions you ask, you can give brainiest to the best answer. Giving brainiest helps the person you gave it to, and it gives back some points you used for the question.

If you have any more questions, feel free to ask. As always, I hope this helps and hope you have a great day and brainiest is always appreciated.
6 0
3 years ago
Read 2 more answers
Using computer software, compare the 2016 year-to-date sales through February to the 2017 year-to-date sales through February fo
JulijaS [17]

Incomplete question. Here's a similar question found in the attachments.

<u>Answer:</u>

<u>General Motors Corp, Chrysler, Ford Motor Company, Toyota Motors sales USA Inc, Nissan North America Inc.</u>

<u>Explanation</u>:

By, using the MS Excel computer software, you would be able to compare the 2016 year-to-date sales through February 2017 year-to-date sales for each manufacturer.

Simply copy the data into the data cells of MS Excel, next use the =sum formula (which should have a minus sign; For example, =SUM (B5 - E5) would give you the difference between the 2016 sales and 2017 sales, only if sales for 2016 is found in column B row 5 and sales for 2017 in column E row 5).

Thus, the results obtained can further be evaluated to determine the manufacturers in the top five with increased sales.

3 0
3 years ago
List and briefly defined categories of security services.
Fynjy0 [20]
There are six categories of security services: authenticiation, access control, data confidentiality, data integrity, nonrepudiation, and availability service. First, is authentication service, which defines as the assurance that the communicator is legitimate and is the one that it claims to be. It can either be peer entity or data origin authentication. Second, access control which is to prevent any unauthorized uses of resources. After one is being authenticiated, then this service limit/controls who access? what accessing rights to the resources are allowed depending on the identified individuals. Data confifentiality: the protection of data from unauthorized disclosure. Data integrity: the assurance that data received are exactly as sent by an authorized entity (e.t.c, contain no modificafion, insertion, deletion, or replay).
7 0
3 years ago
Other questions:
  • 2. You have classes to represent different shapes (see below). You realize you can benefit from inheritance and polymorphism by
    13·1 answer
  • If you have a list of words that you wish me to make into a bulleted list, you must first highlig or ______ The words with the c
    13·1 answer
  • A disadvantage of creating a website with tables, without CSS is
    15·2 answers
  • CAD helps professionals to _____. create a technical drawing give directions to a new location calculate the interest rate of a
    13·2 answers
  • Which of the following are not deducted on a typical pay stub
    12·1 answer
  • Click on the _____ tab on the ribbon to open the backstage view.
    7·1 answer
  • Differentiate between trusted-source-security and antispoofing-security techniques.
    10·1 answer
  • Vegetable farming is a good source of income explain this statement<br>​
    5·1 answer
  • One of the benefits of holding an investment for over a year rather than selling it in less than a year is that the
    14·2 answers
  • An instruction for the computer. Many commands put together to
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!