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
How to be fluent in computer
Setler79 [48]

Explanation:

1. Seeing people do technological innovations, so you have some motivation and inspiration to be fluent in computer

2. Try experimenting and trying stuff, like trying to learn how to code, how the internet work, etc.

3. work more with computers, for example, make a note with OneNote, making digital art with blender, adobe illustrator etc.

4. Try to learn how to be better at learning computer, like, if you do mistakes in your learning journey, try to avoid it next time

5. good luck ;)

7 0
2 years ago
Read 2 more answers
when a picture is downloaded off the internet and then posted to social media, can the social media platform tell it was downloa
Nataly_w [17]
Short answer yes. kinda long answer people can scan the photo and easily see or they can just look up the same image
4 0
2 years ago
In this scenario, two friends are eating dinner at a restaurant. The bill comes in the amount of 47.28 dollars. The friends deci
pickupchik [31]

Answer:

The java program for the given scenario is as follows.

import java.util.*;

import java.lang.*;

public class Main

{

   //variables for bill and tip declared and initialized

   static double bill=47.28, tip=0.15;

   //variables for total bill and share declared

   static double total, share1;

public static void main(String[] args) {

    double total_tip= (bill*tip);

    //total bill computed

    total = bill + total_tip;

    //share of each friend computed

    share1 = total/2;

    System.out.printf("Each person needs to pay: $%.2f", share1);  

}

}

Explanation:

1. The variables to hold the bill and tip percent are declared as double and initialized with the given values.

static double bill=47.28, tip=0.15;

2. The variables to hold the values of total bill amount and total tip are declared as double.

3. All the variables are declared outside main() and at class level, hence declared as static.

4. Inside main(), the values of total tip, total bill and share of each person are computed as shown.

double total_tip= (bill*tip);

total = bill + total_tip;

share1 = total/2;

5. The share of each person is displayed to the user. The value is displayed with only two decimal places which is assured by %.2f format modifier. The number of decimal places required can be changed by changing the number, i.e. 2. This format is used with printf() and not with println() method.

System.out.printf("Each person needs to pay: $%.2f", share1);  

6. The program is not designed to take any user input.

7. The program can be tested for any value of bill and tip percent.

8. The whole code is put inside a class since java is a purely object-oriented language.

9. Only variables can be declared outside method, the logic is put inside a method in a purely object-oriented language.

10. As shown, the logic is put inside the main() method and only variables are declared outside the method.

11. Due to simplicity, the program consists of only one class.

12. The output is attached.

5 0
3 years ago
Read 2 more answers
You are asked to write an app to keep track of a relatively small music library. The app should load song information from a dat
gogolik [260]

Answer:

C++ PROGRAM

Explanation:

6 0
3 years ago
Betty set up an account on a popular social networking website. She wants to know whether the privacy policy is effective for he
Ahat [919]

the info needed to log in

-This would show what is protected in the privacy policy and its related to you since it would show personal data.

-A good Privacy Policy depends on understanding these matters - showing that this is not an agreement to take for granted.

7 0
3 years ago
Other questions:
  • Which operating system became obsolete with the arrival of a more advanced graphical user interfaces
    6·1 answer
  • Software that was designed to serve the needs of a specific company or organization is called:
    5·1 answer
  • In 1988, Robert Morris, Jr. launched a program called the _________ that used weaknesses in e-mail programs and operating system
    5·1 answer
  • I NEED IT FOR TODAY FOR KEYBOARDING TEST! GIVE ME CORRECT ANSWER PLZ!
    12·2 answers
  • Which of the following is true? Group of answer choices worst case time of Heapsort is better than worst cast time of Quicksort
    10·1 answer
  • Write a program that will sort an array of data using the following guidelines - DO NOT USE VECTORS, COLLECTIONS, SETS or any ot
    10·1 answer
  • Write a class Bug that models a bug moving along a horizontal line. The bug moves either to the right or left. Initially, the bu
    7·1 answer
  • A person who creates a computer virus is a (1)system analyst (2) techician(3) programmer​
    11·2 answers
  • Explain the history of America ​
    14·2 answers
  • processing C. have only one function, e.g. control traffic lights in a town, games machines 7 To create a formula, you first: A.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!