The SWITCH example: an outline 1. The problem: The program must verify if the string entered from the keyboard is in a valid month/date/year format. It also will report if the input year is a leap year. 2. Problem analysis: - Decide on the format. Let it be MM/DD/YYYY. We can view this as a StringTokenizer object. - How to define which year is a leap year? year % 4 must be zero for leap years. - How to define if the month entered is valid? It value must be a number between 1 and 12. - How to define if the entered date is valid? It depends on the month, so the month value should be taken into account also. For months 1, 3, 5, 7, 8, 10 and 12, the date is valid if its value is between 1 and 31; for months 4, 6, 9 and 11, the date is valid if its value is between 1 and 30; month 2 is special -- in leap years it has 29 days, in non-leap years it has 28 days. 3. The algorithm in pseudo code: Step 1: first draft. 1. Input the date. 2. Split the date into month, day and year. 3. Verify if the date and month are valid. 4. Output the result. Step 2: second draft. 1. Input the date as a StringTokenizer object. 2. Use the nextToken method to split the date into month, day and year. 3. To verify the date and month: - Use the switch statement, and consider each month as a separate case. BUT, convert the String object month to an integer, because the selector of the switch statement must be of an ordinal data type. - For months 1, 3, 5, 7, 8, 10 and 12 -- max 31 days, min 1 day. - For months 4, 6, 9 and 11 -- max 30 days, min 1 day. - For month 2 -- check if the year is leap. If yes, max 29 days, min 1 day; if no, max 28 days, min 1 day. - For all other values of month -- error. 4. Report if the year is leap, and if the date entered is valid. 5. Testing: Design an appropriate set of test cases to test all branches of the algorithm.