/*
 * Created on Dec 9, 2004
 *
 * Lecture class which contains the main method for examples done
 * in lectures for CS1020-001 Winter 2004-2005. 
 */
package cs1020;

import javax.swing.*;
import java.util.*;

/**
 * @author t a y l o r@msoe.edu
 *
 * Lecture class which contains the main method for examples done
 * in lectures for CS1020-001 Winter 2004-2005. 
 */
public class Lecture {

    /**
     * Exception handling
     * 
     * @author t a y l o r@msoe.edu
     * 
     * @param args Currently ignored
     */
    public static void main(String[] args) {

        String word = "word";
        int x = 3;
        Wrapper y = new Wrapper(x);

        System.out.println(word + x + y.val);
        
        hmm(word, x, y);
        
        System.out.println(word + x + y.val);
        
    }
    
    public static void hmm(String i, int j, Wrapper k) {
        i = "wordless";
        j = 4;
        k.val = 6;
    }    
/*        GregorianCalendar today = new GregorianCalendar();
        int age = -1;
        while(age<0) {
            try {
                age = getAge("How old are you?");
            } catch (AgeInputException e) {
                JOptionPane.showMessageDialog(null, e.getMessage()
                        + "\nShould be between " + e.lowerBound() +
                        " and " + e.upperBound());
    	    }
        }
        int thisYear = today.get(Calendar.YEAR);
        int yearBorn = thisYear - age;
        int hadBDay = JOptionPane.showConfirmDialog(null,
                "Already had your birthday this year?",
                "Y/N",
                JOptionPane.YES_NO_OPTION);
        if(hadBDay == JOptionPane.NO_OPTION) {
            --yearBorn;
        }
        JOptionPane.showMessageDialog(null, "You were born in " + yearBorn);
*/
    
    public static int getAge(String prompt) throws AgeInputException {
        int age = 4;
        boolean done = false;
        while(!done) {
            String ans = JOptionPane.showInputDialog(null, prompt);
	        try {
	            age = Integer.parseInt(ans);
	            if(age<0 || age>150) {
	                throw new AgeInputException(0, 150, age);
	            }
	            done = true;
	        } catch (NumberFormatException e) {
	            JOptionPane.showMessageDialog(null, "Enter digits!");
	        }
        }
        return age;
    }
}