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 are examples of copyrighted online materials? Check all that apply.
Stella [2.4K]
The answers are 1, 3, and 5.
7 0
3 years ago
Read 2 more answers
To reduce the number of used digital outputs of the microcontroller, the display board is connected to the main board through th
Luda [366]

Answer:

The program in Python is as follows:

BCD = ["0001","0010","0011","0100","0101","0110","0111"]

num = input("Decimal: ")

BCDValue = ""

valid = True

for i in range(len(num)):

   if num[i].isdigit():

       if(int(num[i])>= 0 and int(num[i])<8):

           BCDValue += BCD[i]+" "

       else:

           valid = False

           break;

   else:

       valid = False

       break;

if(valid):

   print(BCDValue)

else:

   print("Invalid")

Explanation:

This initializes the BCD corresponding value of the decimal number to a list

BCD = ["0001","0010","0011","0100","0101","0110","0111"]

This gets input for a decimal number

num = input("Decimal: ")

This initializes the required output (i.e. BCD value)  to an empty string

BCDValue = ""

This initializes valid input to True (Boolean)

valid = True

This iterates through the input string

for i in range(len(num)):

This checks if each character of the string is a number

   if num[i].isdigit():

If yes, it checks if the number ranges from 0 to 7 (inclusive)

       if(int(num[i])>= 0 and int(num[i])<8):

If yes, the corresponding BCD value is calculated

           BCDValue += BCD[i]+" "

       else:

If otherwise, then the input string is invalid and the loop is exited

<em>            valid = False</em>

<em>            break;</em>

If otherwise, then the input string is invalid and the loop is exited

<em>    else:</em>

<em>        valid = False</em>

<em>        break;</em>

If valid is True, then the BCD value is printed

<em>if(valid):</em>

<em>    print(BCDValue)</em>

If otherwise, it prints Invalid

<em>else:</em>

<em>    print("Invalid")</em>

7 0
3 years ago
Operations that run in protected mode must go through which of the following before they can access a computer’s hardware? A. Ke
HACTEHA [7]

Answer:

Option A (Kernal) seems to be the right answer.

Explanation:

  • A Kernel appears to be the central component of such an OS. This handles machine as well as hardware activities, including most importantly storage as well as CPU power.
  • This manages the majority of the initialization as well as program input/output requests, converting them into CPU data-processing commands.

The other given option are not related to the given circumstances. So that option A would be the right answer.

3 0
3 years ago
Point out the wrong statement :
hoa [83]

Answer:

d. None of the mentioned

Explanation:

Cloud computing can be defined as a type of computing that requires shared computing resources such as cloud storage (data storage), servers, computer power, and software over the internet rather than local servers and hard drives.

Generally, cloud computing offers individuals and businesses a fast, effective and efficient way of providing services.

Cloud computing comprises of three (3) service models and these are;

1. Platform as a Service (PaaS).

2. Infrastructure as a Service (IaaS).

3. Software as a Service (SaaS).

All of the following statements are true and correct because they are standard internet protocols;

I. Virtual appliances are becoming a very important standard cloud computing deployment object. This depicts the Platform as a Service (PaaS).

II. Cloud computing requires some standard protocols.

III. Cloud computing relies on a set of protocols needed to manage interprocess communications.

8 0
3 years ago
How to type the plus sign +
zmey [24]

Answer:

you just did it. its on da keyboard

Explanation:

hold shift and click the equal sign

Shift + = = +

7 0
2 years ago
Read 2 more answers
Other questions:
  • All of the following are forms of verbal communication except
    12·2 answers
  • You recently upgraded your computer and added an extra 512 MB of RAM. Consequently, you want to increase your swap space by addi
    10·1 answer
  • What is an example of a memo
    9·1 answer
  • The algorithm ____ is used to find the elements in one range of elements that do not appear in another range of elements.
    5·1 answer
  • A function ________ contains the statements that make up the function.
    5·1 answer
  • Select the correct answer
    5·2 answers
  • How much is this worth in dollars​
    9·1 answer
  • It is usually simple to delete old posts and online conversations if they make you look bad.
    5·1 answer
  • A good information that contains the facts necessary for decision makers to solve a problem is characterized by the __________.
    15·2 answers
  • Do you guys answer questions about cyber security?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!