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
Quiero saber que tipo de gama es mi laptop (gama baja, media, o alta)
nalin [4]

Answer:

I think the answer would be 60x something but I'm not for sure

8 0
2 years ago
The function of an audio mixer is to _____. layer audio tracks at their ideal volume combine, control, and route audio signals f
larisa [96]

Answer: combine, control, and route audio signals from inputs to outputs

Explanation:

A audio mixer is refered to as the sound mixer or the mixing console and it's an electronic device that's used for mixing, and combining several audio signals and sounds.

The input to the console is the microphone. The audio mixer can also be used in controlling digital or analog signals. These are then summed up in producing output signals.

Therefore, the function of the audio mixer is to combine, control, and route audio signals from inputs to outputs.

7 0
2 years ago
File formats are linked to certain programs.<br><br> True<br> False
Lostsunrise [7]
What was the answer?
7 0
3 years ago
Read 2 more answers
What is the difference between ROM and RAM
Blababa [14]

Answer:

ROM : Read Only Memory.

RAM : Random Ascess Memory.

8 0
2 years ago
Read 2 more answers
JAVA PROGRAMMING
VashaNatasha [74]

Answer:

See explaination

Explanation:

import java.util.Scanner;

public class GtldValidation {

public static void main (String [ ] args) {

Scanner scnr = new Scanner(System.in);

// Define the list of valid core gTLDs

String [ ] validCoreGtld = { ".com", ".net", ".org", ".info" };

// FIXME: Define an array named validRestrictedGtld that has the names

// of the restricted domains, .biz, .name, and .pro

String [] validRestrictedGtld={".biz",".name",".pro"};

String inputName = "";

String searchName = "";

String theGtld = "";

boolean isValidDomainName = false;

boolean isCoreGtld = false;

boolean isRestrictedGtld = false;

int periodCounter = 0;

int periodPosition = 0;

int i = 0;

System.out.println("\nEnter the next domain name (<Enter> to exit): ");

inputName = scnr.nextLine();

while (inputName.length() > 0) {

searchName = inputName.toLowerCase();

isValidDomainName = false;

isCoreGtld = false;

isRestrictedGtld = false;

// Count the number of periods in the domain name

periodCounter = 0;

for (i = 0; i < searchName.length(); ++i) {

if (searchName.charAt(i) == '.') {

++periodCounter;

periodPosition = i;

}

}

// If there is exactly one period that is not at the start

// or end of searchName, check if the TLD is a core gTLD or a restricted gTLD

if ((periodCounter == 1) &&

(searchName.charAt(0) != '.') &&

(searchName.charAt(searchName.length() - 1) != '.')) {

isValidDomainName = true;

}

if (isValidDomainName) {

// Extract the Top-level Domain name starting at the period's position. Ex:

// If searchName = "example.com", the next statement extracts ".com"

theGtld = searchName.substring(periodPosition);

i = 0;

while ((i < validCoreGtld.length) && (!isCoreGtld)) {

if(theGtld.equals(validCoreGtld[i])) {

isCoreGtld = true;

}

else {

++i;

}

}

// FIXME: Check to see if the gTLD is not a core gTLD. If it is not,

// check to see whether the gTLD is a valid restricted gTLD.

// If it is, set isRestrictedGtld to true

}

System.out.print("\"" + inputName + "\" ");

if (isValidDomainName) {

System.out.print("is a valid domain name and ");

if (isCoreGtld) {

System.out.println("has a core gTLD of \"" + theGtld + "\".");

}

else if (isRestrictedGtld) {

System.out.println("has a restricted gTLD of \"" + theGtld + "\".");

}

else {

System.out.println("does not have a core gTLD."); // FIXME update message

}

}

else {

System.out.println("is not a valid domain name.");

}

System.out.println("\nEnter the next domain name (<Enter> to exit): ");

inputName = scnr.nextLine();

}

return;

}

}

8 0
3 years ago
Other questions:
  • In the electric series, which one of the following materials is the most negatively charged? A. Silk B. Sealing wax C. Teflon D.
    7·2 answers
  • What privacy issues have arisen with webcams in mobile devices?
    8·1 answer
  • How has the use of computers impacted business
    13·2 answers
  • Which button would you use to insert a downloaded video clip on your computer into a slide?
    15·2 answers
  • In Access, it is possible to have _______________ fields, that is, fields that can contain more than one value.
    9·1 answer
  • Recall the binary search algorithm.1. Using the algorithm/algorithmic environment, give pseudocode using a for loop.AnswerMy alg
    5·1 answer
  • FOLLOW INSTRUCTIONS BELOW , WRITTEN IN JAVA LANGUAGE PLEASE AND THANK YOU !
    10·1 answer
  • Which of the following is a key aspect of any IT position? installation of fiber optic cables
    14·2 answers
  • Marta is creating a program that will guide the user through a series of physical exercises. She wants the program to coach the
    12·2 answers
  • What type of attack occurs when the threat actor snoops and intercepts the digital data transmitted by the computer and resends
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!