Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program that asks the user to enter the month ( letting the user enter a

ID: 640819 • Letter: W

Question

write a program that asks the user to enter the month ( letting the user enter an integer of 1 through 12) and the year. T he program should then display the number of days in that month. use the following criteria to identify leap year.

1. Determine whether the year is divisible by 100. if it is, then it is a leap year if and only if it is divisible by 400.

2. if the year is not divisible by 100, then it isa leap year if and if only it is divisible by 4.

Explanation / Answer

public class Month { private int monthNumber; public Month(int monthNumber) { if (monthNumber < 1 || monthNumber > 12) { throw new IllegalArgumentException( "Month number must be between 1 and 12"); } this.monthNumber = monthNumber; } public int getLength() { return monthLengths[monthNumber - 1]; // indexes start at 0 } private static int[] monthLengths = { 31, // January 28, // February 31, // March . . . } }