Lab7: Question1

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;
   }
Test Case Path Activity
(year=0 month=1) throw YearOutOfBounds
(year=1 month=1) (n=31 return)
(year=1 month=4) (n=30 return)
(year=4 month=2) (n=29 return)
(year=1 month=2) (n=28 return)
(year=1 month=13) throw MonthOutOfBounds
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;
   }
Test Case Path Activity
(year=4) (leap=true)
(year=1900) (leap=false)
(year=2000) (leap=true)
(year=1) (leap=false)

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().