Java Write Method Isleapyear Parameter Type Int Named Year Parameter Needs Greater Equal 1 Q43799752
(Java) Write a method isLeapYear with a parameter of type intnamed year.
The parameter needs to be greater than or equal to 1 and lessthan or equal to 9999.
If the parameter is not in that range return false.
Otherwise, if it is in the valid range, calculate if the year isa leap year and return true if it is, otherwise return false.
A year is a leap year if it is divisible by 4 but not by 100, orit is divisible by 400.
Examples of input/output:
* isLeapYear(-1600); → should return false since the parameteris not in the range (1-9999)
* isLeapYear(1600); → should return true since 1600 is a leapyear
* isLeapYear(2017); → should return false since 2017 is not aleap year
* isLeapYear(2000); → should return true because 2000 is a leapyear
NOTE: The solution to the Leap Year coding exercise earlier inthe course created the isLeapYear method. You can use that solutionif you wish.
Write another method getDaysInMonth with two parameters monthand year. Both of type int.
If parameter month is < 1 or > 12 return -1.
If parameter year is < 1 or > 9999 then return -1.
This method needs to return the number of days in the month. Becareful about leap years they have 29 days in month 2(February).
You should check if the year is a leap year using the methodisLeapYear described above.
Examples of input/output:
* getDaysInMonth(1, 2020); → should return 31 since January has31 days.
* getDaysInMonth(2, 2020); → should return 29 since February has29 days in a leap year and 2020 is a leap year.
* getDaysInMonth(2, 2018); → should return 28 since February has28 days if it’s not a leap year and 2018 is not a leap year.
* getDaysInMonth(-1, 2020); → should return -1 since theparameter month is invalid.
* getDaysInMonth(1, -2020); → should return -1 since theparameter year is outside the range of 1 to 9999.
HINT: Use the switch statement.
NOTE: Methods isLeapYear and getDaysInMonth need to be publicstatic like we have been doing so far in the course.
NOTE: Do not add a main method to solution code.
Expert Answer
Answer to (Java) Write a method isLeapYear with a parameter of type int named year. The parameter needs to be greater than or equa…
OR