Correct the faults in the isLeapYear() and getNumDaysInMonth() methods of Figure 11-12 and generate test cases using the path testing methods. Are the test cases you found different than those of Table 11-14 and Figure 11-13? Why? Would the test cases you found uncover the faults you corrected?

What will be an ideal response?


```

public class MonthOutOfBounds extends Exception {...};

public class YearOutOfBounds extends Exception {...};

public class MyGregorianCalendar {

public static boolean isLeapYear(int year) {

boolean leap;

if ((year%400) == 0) {

leap = true;

} else if ((year%100) == 0) {

leap = false;

} else if ((year%4) == 0) {

leap = true;

} else {

leap = false;

}

return leap;

}

public static int getNumDaysInMonth(int month, int year)

throws MonthOutOfBounds, YearOutOfBounds {

int numDays;

if (year < 1) {

throw new YearOutOfBounds(year);

}

if (month == 1 || month == 3 || month == 5 || month == 7 ||

month == 10 || month == 12) {

numDays = 31;

} else if (month == 4 || month == 6 || month == 9 || month == 11) {

numDays = 30;

} else if (month == 2) {

if (isLeapYear(year)) {

numDays = 29;

} else {

numDays = 28;

}

} else {

throw new MonthOutOfBounds(month);

}

return numDays;

}

...

}

```

Figure 11-1 Corrected impl

Computer Science & Information Technology

You might also like to view...

In programming we use the term ____________ to mean a sequence of characters that could be enclosed in quotation marks “…”.

a. statement b. thread c. word d. string

Computer Science & Information Technology

If you point to a command on a menu that has an arrow on its right edge, a ____ displays another list of commands.

a. submenu b. hidden command c. hidden menu d. none of the above

Computer Science & Information Technology

Sorting enables you to target a mailing to individuals in a specific state or ZIP code area.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

COGNITIVE ASSESSMENT Your company has elected to offload all storage management to an outside organization. What is the term for this?

A. fiber channeling B. RAID C. NAS D. outsourcing

Computer Science & Information Technology