Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use this shell http://www.heypasteit.com/clip/0IJF6G Problem: Write a program that will input a numeric month from the user and outputs the number of the days in

Use this shell

http://www.heypasteit.com/clip/0IJF6G

Problem:

Write a program that will input a numeric month from the user and outputs the number of the days in the given month.

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.

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 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

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions

Question

=+ How can they be incorporated into social media content?

Answered: 1 week ago

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago

Question

2. What, according to Sergey, was strange at this meeting?

Answered: 1 week ago