/**
 * If Switch Demo.
 * Original SwitchDemo is from 
 * https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
 * Added code to do this via If Then Else.
 * @author Alvin Chao
 * @version  2-15-17
 */
 
public class IfSwitchDemo {

    /**
     * Main.
     * @param args not used.
     */
     
    public static void main(String[] args) {

        int month = 2;
        int year = 2000;
        int numDays = 0;
        int ifNumDays = 0;

        switch (month) {
            case 1: case 3: case 5:
            case 7: case 8: case 10:
            case 12:
                numDays = 31;
                break;
            case 4: case 6:
            case 9: case 11:
                numDays = 30;
                break;
            case 2:
                if (((year % 4 == 0) 
                    && !(year % 100 == 0))
                    || (year % 400 == 0)) {
                    numDays = 29;
                } else {
                    numDays = 28;
                }
                break;
            default:
                System.out.println("Switch default - Invalid month.");
                break;
        }
        //--------------if then 
        if ((month == 1)
            || (month == 3)
            || (month == 5)
            || (month == 7)
            || (month == 8)
            || (month == 10)
            || (month == 12)) { 
            ifNumDays = 31;
        } else if ((month == 4)
            || (month == 6)
            || (month == 9)
            || (month == 11)) {
            ifNumDays = 30;
        } else {
            if (((year % 4 == 0) 
                    && !(year % 100 == 0))
                    || (year % 400 == 0)) {
                ifNumDays = 29;
            } else {
                ifNumDays = 28;
            }
        }        
        System.out.println("Switch Number of Days = "
                           + numDays);
        System.out.println("If Number of Days = "
                           + ifNumDays);
                                   
    }
}
