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.javaPreview the document 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. /***************************************************************************** * Chapter 4 Lab * Days in Month and Leap Year ****************************************************************************/ import java.util.Scanner; public class DaysInMonthShell { // You do not need to add anything to this method public static void main(String[] args) { Scanner console = new Scanner(System.in); runProgram(console); } // Input: Scanner object "console" to read from keyboard // Returns: None // Description: Prompt the user to enter an integer for the month, // verify that it is in the correct range and output error if not. // Call methods to get the month name and the number of days // Output the results public static void runProgram(Scanner console) { } // Input: monthNum as an integer // Returns: The string for that month // Description: Do not print anything to the string, only return the name. // There should be validation ahead of time to ensure that the monthNum // is in the correct range, return "Error" if it isn't public static String getMonthName(int monthNum) { return ""; } // Input: monthNum as an integer, console Scanner object to pass to the // getNumDaysFeb in case it needs to be called. // Returns: the number of days in that month // Description: For any month but 2 (February), return the number of months. // but if it is 2, call the getNumDaysFeb method to prompt for // the year to determine the number of days in February public static int getNumDays(int monthNum, Scanner console) { return 0; } // Input: Scanner object "console" to read from keyboard // Returns: The number of days in February // Description: Prompt the user to enter the year, determine if it is a leap year // and return 29 if it is, 28 otherwise public static int getNumDaysFeb(Scanner console) { return 0; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
