import java.util.Scanner; /** * A program to demo basics of exception handling structures. * * @author Lisa C. Kaczmarczyk. * Created Sep 5, 2006. */ public class NutritionalIntake { /** * Driver only. * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { NutritionalIntake.getWeekday(); } /** * tell the user what they get to eat based upon how well they follow directions. * * @param args * @throws Exception */ public static void getWeekday() throws Exception { // find out if it is a weekday and reward the user accordingly. Scanner scannerObject = new Scanner(System.in); int day; System.out.println("Use a number to tell me what weekday it is:"); System.out.println("1 - Monday, 2-Tuesday, 3-Wednesday, 4-Thursday, 5-Friday"); day = scannerObject.nextInt(); processIt(day); } /** * Process the day entered by the user by giving an encouraging (or not-so- * encouraging message). * * @param day * @throws Exception * */ private static void processIt(int day) throws Exception { if (day == 6 || day == 7) throw new Exception("Are you trying to say it is the weekend???"); else if (day > 7) throw new Exception("There aren't that many days in a week"); else if (day < 1) throw new Exception("Um...That makes no sense"); System.out.println("Because it is a weekday you get to eat gummy bears. Good Job!"); } }