import java.util.*; 

class BigMac {
  public static void main(String[] args) {

    // Stack<Integer> b = new Stack<Integer>(); 
    // System.out.println( b.peek() ); 

    System.out.println("Welcome to Exam Problem One.");
    Scanner a = new Scanner(System.in);  
    System.out.println( a );     
    System.out.print("Enter number: "); 
    int number = a.nextInt(); 
    System.out.println("You have entered: " + number); 
    Stack<Integer> stack; 
    stack = new Stack<Integer>(); 
    System.out.println( stack ); 
    while (number > 0) {
        int digit = number % 10; 
        stack.push( digit ); 
        System.out.println( stack ); 
        number = number / 10; 
        System.out.println("Number becomes: " + number); 
    }  
    System.out.println("Stack is: " + stack); 
    while (true) {
        try { 
           Integer element = stack.pop();
           System.out.print( element + " "); 
           // System.out.println("Stack now: " + stack); 
        } catch (EmptyStackException e) {
           System.out.println("Stack empty. Thanks for using this program.");
           break;  
        }
    } 
  } 
}

/*

  1. Define a class with a main. Compile and run it. 
  2. Create a Scanner to read from the user. 
  3. Ask the user for an integer. Read it. Print it back.
  4. Let's create a Stack. 
  5. Take the last digit of the number and put it in the stack.   
  6. Get rid of that digit, then repeat the previous step. 
  7. Stop the loop when the number becomes 0. 
  8. I read how the top of the stack is to the right when printed. 
  9. Pop the stack one element and print it.
  9.1 Quick test to see what s.peek() on an empty stack does.
      Turns out I get an exception. 
      http://docs.oracle.com/javase/6/docs/api/java/util/Stack.html
      So I could use .empty() or .isEmpty() or .size() == 0
  9.2 Instead I noticed that I get EmptyStackException 
 10. Repeat step 9 until the stack is empty, printing each element. 
 */