Question
Write a program that will input a numeric month from the user and outputs the number of the days in the given month. Use the
Write a program that will input a numeric month from the user and outputs the number of the days in the given month. Use the shell provided for you. You may deviate from the shell but you must use methods and meet the regular requirements for this assignment.
If the user enters 2, ask the user for the year to find out if the year is a leap year or not.
Output:
Print out the name of the month and number of days in that month.
Shell: DaysInMonthShell.java
Requirements:
Just to give you practice using switch statements you are required to use 2 switch statements for this program.
If statement will be used to assign the appropriate name of the month to a String variable (monthName).
Switch statement will be used to assign the number of days to an int variable.
Note: This switch statement must have only one break/return for all the 31day months and only one break for all the 30 day months.
The saying goes:
Thirty days has September, April, June, and November. All the rest have 31, excepting February, Which has 28 till leap year makes it 29.
The rule for leap years is:
If the year is a multiple of 4 it is a leap year, unless it is a multiple of 100, then it is not a leap year, unless it is a multiple of 400, then it is a leap year.
if (((year % 4 == 0 ) && ((year % 100 != 0)) || (year % 400 == 0))) daysOfMonth = 29; else daysOfMonth = 28;
_____________________________________________________________________________
Example Run 1:
Please enter an integer for a month (1-12): 5 There are 31 days in May.
_____________________________________________________________________________
Example Run 2:
Please enter an integer for a month (1-12): 2 What year are you interested in? 2000 In the year 2000: There are 29 days in February.
_____________________________________________________________________________
Example Run 3:
Please enter an integer for a month (1-12): 13 Error: you input 13 and that is not in the range 1 to 12.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started