This question already has an answer here:
Say you want to replace a long chain of if's with a switch-case, how do you handle a possible input that is not one of the cases that you have set. For example:
switch(medicalPlan) {
case 3: employeeList.add(new FullTime(inLast, inFirst,
inSoc, inSal, NO_PREMIUM, NO_OFFICE,
NO_HOSPITAL));
break;
case 2: employeeList.add(new FullTime(inLast, inFirst,
inSoc, inSal, LOW_PREMIUM, LOW_OFFICE,
LOW_HOSPITAL));
break;
case 1: employeeList.add(new FullTime(inLast, inFirst,
inSoc, inSal, HIGH_PREMIUM, HIGH_OFFICE,
HIGH_HOSPITAL));
break;
}//end of switch case for medical plan
Is there some form of else that can be used inside of a switch-case?
Aucun commentaire:
Enregistrer un commentaire