getNumDaysInMonth() | ||||||||||||||
public int getNumDaysInMonth(int month, int year){ int numDays; a if(year < 1) b throw new YearOutOfBounds(year); c if(month==1 || month==3 || month==5 || month==7 || month==8 || month== 10 || month==12){ d numDays = 31; e }else if(month==4 || month==6 || month==9 || month==11){ f numDays = 30; g }else if(month==2){ h if(isLeapYear(year)){ i numDays = 29; }else{ j numDays = 28; } } else{ k throw new MonthOutOfBounds(month); } l return numDays; } |
||||||||||||||
|
||||||||||||||
![]() |
||||||||||||||
isLeapYear() | ||||||||||||||
public static boolean isLeapYear(int year){ boolean Leap; n if(((year%4==0) && (year%100!=0) || (year%400==0)) o leap = true; else p leap = false; q return leap; } |
||||||||||||||
|
||||||||||||||
![]() |
||||||||||||||
Discussion: Our test case for getNumDaysInMonth() is different only in that the input (year=1 month=1) produces (n=31 return) as output, instead of n=32. Our test case for isLeapYear() is different in that we test for non-leap years divisible by 100 and leap years divisible by 400. Our test cases for both functions would have found the faulst in the original code using the (year=1 month=1) input for getNumDaysInMonth() and the (year=1900) input for isLeapYear(). |