Question: JAVA!! This is my assignment. And i have posted my code below. My question is the following: If the user input is invalid and the
JAVA!! This is my assignment. And i have posted my code below. My question is the following: If the user input is invalid and the "else" statement is executed, how can I make the System.out.println("Your Sign is " + sign); that comes after the else statement not execute, without having to have the system.out.print in every if/else if statement. So if the user input is invalid, the output should be ONLY THIS: "Invalid Entry. Please run the program to try again."

import java.util.Scanner;
public class Sign {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int month, day;
System.out.println("What's your sign?");
System.out.print("Please enter the month of your birth (1-12): ");
month = input.nextInt();
System.out.print("Please enter the day of your birth (1-31): ");
day = input.nextInt();
String sign = "";
if ((month == 3 && (day >= 21 && day = 1 && day
sign = "Aries";
}
else if ((month == 4 && (day >= 20 && day = 1 && day
sign = "Taurus";
}
else if ((month == 5 && (day >= 21 && day = 1 && day
sign = "Gemini";
}
else if ((month == 6 && (day >= 22 && day = 1 && day
sign = "Cancer";
}
else if ((month == 7 && (day >= 23 && day = 1 && day
sign = "Leo";
}
else if ((month == 8 && (day >= 23 && day = 1 && day
sign = "Virgo";
}
else if ((month == 9 && (day >= 23 && day = 1 && day
sign = "Libra";
}
else if ((month == 10 && (day >= 23 && day = 1 && day
sign = "Scorpio";
}
else if ((month == 11 && (day >= 22 && day =1 && day
sign = "Sagittarius";
}
else if ((month == 12 && (day >= 22 && day = 1 && day
sign="Capricon";
}
else if ((month == 1 && (day >= 20 && day = 1 && day
sign="Aquarius";
}
else if((month == 2 && (day >= 19 && day = 1 && day
sign="Pieces";
}
else {
System.out.println("Invalid Entry. Please run the program to try again.");
}
System.out.println("Your Sign is " + sign);
input.close();
}
}
Assignment 11.1: What's Your Sign? (10 pts) For this assignment, let's write an astrology program Welcome the user (see sample output below) Prompt the user to enter a numerical value (1-12) for the month of his/her birth (see sample output) Prompt the user to enter a numerical value (1-31) for the day of his/her birth (see sample output) Then, determine the user's sign based on their input. IX X Aries Taurus Gemini Cancer March 21-April 19 April 20-May 20 May 21 -June 21 June 22 - July 22 Leo July 23 - August 2 August 23 - September 22 Virgo Libra September 23 - October 22 October 23 November 21 Scorpio Sagittarius November 22 - December 21 Capricorn December 22 -January 19 Aquarius January 20 February 18 Pisces February 19 - March 20 .Expect to need to use if, else if and else statements . Expect to use logical operators (&&, |I) . Submit your source code in a file called Sign.java to Canvas when finished Your sample output must be identical to mine What's your sign? Please enter the month of your birth (1-12): 3 Please enter the day of your birth (1-31): 3 Your Sign is Pisces
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
