Question

In: Computer Science

Ive been stuck on this problem for a while. any advice would be appreciated. Write a...

Ive been stuck on this problem for a while. any advice would be appreciated.

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 int 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: Blue 65

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

this is what i have so far, its LONG but ive gone through this with a fine toothed comb and nothing works for me.

import java.util.Scanner;

public class LabProgram {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String inputMonth = sc.next();

int inputDay = sc.nextInt();

{

if (inputMonth.equals("December") && inputDay >= 21 && inputDay <= 31){

System.out.println("Winter");}

else if (inputMonth.equals("January") && inputDay >= 1 && inputDay <= 31){

System.out.println("Winter");}

else if (inputMonth.equals("February") && inputDay >= 1 && inputDay <= 29)

System.out.println("Winter");

else if (inputMonth.equals("March") && inputDay >= 1 && inputDay <= 19)

System.out.println("Winter");

else if (inputMonth.equals("March") && inputDay >= 20 && inputDay <= 31)

System.out.println("Spring");

else if (inputMonth.equals("April") && inputDay >= 1 && inputDay <= 30)

System.out.println("Spring");

else if (inputMonth.equals("May") && inputDay >= 1 && inputDay <= 29)

System.out.println("Spring");

else if (inputMonth.equals("June") && inputDay >= 1 && inputDay <= 20)

System.out.println("Summer");

else if (inputMonth.equals("June") && inputDay >= 21 && inputDay <= 30)

System.out.println("Summer");

else if (inputMonth.equals("july") && inputDay >= 1 && inputDay <= 29)

System.out.println("Summer");

else if (inputMonth.equals("August") && inputDay >= 1 && inputDay <= 29)

System.out.println("Summer");

else if (inputMonth.equals("September") && inputDay >= 1 && inputDay <= 21)

System.out.println("Summer");

else if (inputMonth.equals("September") && inputDay >= 21 && inputDay <= 29)

System.out.println("Autumn");

else if (inputMonth.equals("October") && inputDay >= 1 && inputDay <= 31)

System.out.println("Autumn");

else if (inputMonth.equals("November") && inputDay >= 1 && inputDay <= 29)

System.out.println("Autumn");

else if (inputMonth.equals("December") && inputDay >= 1 && inputDay <= 20)

System.out.println("Autumn");

}

else{

System.out.println("Invalid");

{

thank you.

Solutions

Expert Solution

SOLUTION-
I have corrected your code and gave it below with screenshot :)

Actually in yr code there is "{" before if case that is invalid so i have given it coreectly below

CODE-

//java code
import java.util.Scanner;
//main class
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String inputMonth = sc.next();
int inputDay = sc.nextInt();
if (inputMonth.equals("January") && inputDay >= 1 && inputDay <= 31)
System.out.println("winter");
else if (inputMonth.equals("February") && inputDay >= 1 && inputDay <= 29)
System.out.println("winter");
else if (inputMonth.equals("April") && inputDay >= 1 && inputDay <= 30)
System.out.println("spring");
else if (inputMonth.equals("May") && inputDay >= 1 && inputDay <= 30)
System.out.println("spring");
else if (inputMonth.equals("July") && inputDay >= 1 && inputDay <= 31)
System.out.println("summer");
else if (inputMonth.equals("August") && inputDay >= 1 && inputDay <= 31)
System.out.println("summer");
else if (inputMonth.equals("October") && inputDay >= 1 && inputDay <= 31)
System.out.println("autumn");
else if (inputMonth.equals("November") && inputDay >= 1 && inputDay <= 30)
System.out.println("autumn");
else if (inputMonth.equals("March") && inputDay >= 20 && inputDay <= 31)
System.out.println("spring");
else if (inputMonth.equals("June") && inputDay >= 1 && inputDay <= 20)
System.out.println("spring");
else if (inputMonth.equals("June") && inputDay >= 21 && inputDay <= 30)
System.out.println("summer");
else if (inputMonth.equals("September") && inputDay >= 1 && inputDay <= 21)
System.out.println("summer");
else if (inputMonth.equals("September") && inputDay >= 22 && inputDay <= 30)
System.out.println("autumn");
else if (inputMonth.equals("December") && inputDay >= 0 && inputDay <= 20)
System.out.println("autumn");
else if (inputMonth.equals("December") && inputDay >= 21 && inputDay <= 30)
System.out.println("winter");
else if (inputMonth.equals("March") && inputDay >= 1 && inputDay <= 19)
System.out.println("winter");
else
System.out.println("invalid");
}
}

SCREENSHOT-

IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

Any advice or recommendation would be greatly appreciated You are the sport agent for a rising...
Any advice or recommendation would be greatly appreciated You are the sport agent for a rising basketball star just drafted in the first round. Your client has two offers on the table option $90 million dollars over 5 years or option $30 million signing bonus and 40 million over the next 3 yrs. What option do you recommend? How does the time value of money impact your decision?
Having some trouble with this python question. An answer would be greatly appreciated! #Write a function...
Having some trouble with this python question. An answer would be greatly appreciated! #Write a function called are_anagrams. The function should #have two parameters, a pair of strings. The function should #return True if the strings are anagrams of one another, #False if they are not. # #Two strings are considered anagrams if they have only the #same letters, as well as the same count of each letter. For #this problem, you should ignore spaces and capitalization. # #So, for...
Any ideas on nursing diagnosis? a couple of ideas would be appreciated Sherry, 33, HIV/AIDS. Recently...
Any ideas on nursing diagnosis? a couple of ideas would be appreciated Sherry, 33, HIV/AIDS. Recently discharged after treatment for pyelonephritis, Discharged home on Hospice Care Services. No longer employed since diagnosed. Lives with extended family on the 6th floor of a city housing apartment. Has no insurance.
Hello everyone! I have been stuck on this problem in my python 3 coding class. Is...
Hello everyone! I have been stuck on this problem in my python 3 coding class. Is there anybody who can see what I am doing wrong? The wings are .50 cents each, If I input sour and want 20 wings it should output a 0.15 discount. I just can't get it to work but I feel like I am really close. Thank you Code: #Variables answer = str() wings = int() rate = float() discount = float() subtotal = float()...
Hello, I am stuck on this problem....... A histogram of height measurements among middle students would...
Hello, I am stuck on this problem....... A histogram of height measurements among middle students would most likely be: This was a homework question I am confused because there is no data for how many kids or how tall they were. I am taking a guess thinking that the kids are would be normally distributed? Am I correct? Could you please solve? Thank you normally distributed orthogonal skewed left skewed right
1. What advice would you provide to a company that has been compromised by a hacker?...
1. What advice would you provide to a company that has been compromised by a hacker?
What advice would you provide to a company that has been compromised by a hacker? (6...
What advice would you provide to a company that has been compromised by a hacker? Subject Information Security.
Problem with code. The fixed code would be greatly appreciated! Error messages: PlayerMoveDungeon2.java:21: error: cannot find...
Problem with code. The fixed code would be greatly appreciated! Error messages: PlayerMoveDungeon2.java:21: error: cannot find symbol for (i = 0; i < length; i++) { ^ symbol: variable i location: class PlayerMoveDungeon2 PlayerMoveDungeon2.java:21: error: cannot find symbol for (i = 0; i < length; i++) { ^ symbol: variable i location: class PlayerMoveDungeon2 PlayerMoveDungeon2.java:21: error: cannot find symbol for (i = 0; i < length; i++) { ^ symbol: variable i location: class PlayerMoveDungeon2 PlayerMoveDungeon2.java:22: error: cannot find symbol...
C++ while loop Exercise Write a program that continues to ask the user to enter any...
C++ while loop Exercise Write a program that continues to ask the user to enter any set of numbers, until the user enters the number -1. Then display the total sum of numbers entered and their average. (note that you need to define a counter that counts how many numbers so the average = (sum/n) where n is your counter total. #include <iostream> using namespace std; int main() { int number, n=0, sum=0; cout << "Enter a number to start...
This problem involves a periodic system: while t can be any real number, the dependent variable...
This problem involves a periodic system: while t can be any real number, the dependent variable θ(t) ∈ [0, 2π). Consult chapter 4 of Strogatz. Consider the equation θ ̇ = μ + sin θ. (a) Draw phase portraits for different values of μ, find the bifurcation values of μ, and describe the fixed points and their stability in each regime. (b) Now consider specifically the case where μ is just slightly less than 1: what is true about the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT