// Filename: Donuts7.java
// Written by: Mike Wade
// Last Modified: 11/30/1999
                    
/***************************************************************
 * Program Description:                                        *
 *                                                             *
 * Asks the user to enter the number of donuts she would like. *
 * If there are enough donuts on hand, the program then        *
 * displays the number of donuts wanted, and displays the      *
 * number of donuts remaining in the donut stock.  If there    * 
 * are not enough donuts on hand, the program prints a nasty   *
 * message.  If the user asks for a negative number of donuts, *
 * a sarcastic message is displayed                            *
 ***************************************************************/
 
/******************************************************
 * Program Purpose:                                   *
 *                                                    *
 * This program was written to illustrate the use of: *
 * 1) Wrappers                                        *
 * 2) Reading integers from stdin                     *
 ******************************************************/


import java.io.*;

class Donuts7 {
  
    public static void main (String[] args) throws IOException {
        BufferedReader stdin = new BufferedReader
            (new InputStreamReader(System.in)); // for reading input
        int donutStock = 12;  // Number of donuts we started with
        int donutsWanted;     // Number of donuts requested; read from stdin 
        String inp;           // will hold the line read from stdin
        
        System.out.print("How many donuts would you like? ");
        inp = stdin.readLine();
        donutsWanted = Integer.parseInt(inp);
        
        if (donutsWanted > donutStock) {
            System.out.println("I don't have that many donuts.");
            System.out.println("The Donut Nazi says: No donuts for you!");
        }
        else if (donutsWanted < 0) {
            System.out.println("What does this mean?" + 
                               "  You want to give me donuts?");
            System.out.println("The Donut Nazi says: Gimme!");
        }
        else {
            donutStock = donutStock - donutsWanted;
            System.out.println("Here's your " + donutsWanted + " donuts.");
            System.out.println("I still have " + donutStock 
                               + " donuts remaining.");
        }

        System.out.println();
    }
}
    
/**** Sample output
marge(39)% java Donuts7
How many donuts would you like? 13
I don't have that many donuts.
The Donut Nazi says: No donuts for you!

marge(40)% java Donuts7
How many donuts would you like? -1
What does this mean?  You want to give me donuts?
The Donut Nazi says: Gimme!

marge(41)% java Donuts7
How many donuts would you like? 12
Here's your 12 donuts.
I still have 0 donuts remaining.

marge(42)% java Donuts7
How many donuts would you like? none
Exception in thread "main" java.lang.NumberFormatException: none
        at java.lang.Throwable.fillInStackTrace(Native Method)
        at java.lang.Throwable.<init>(Throwable.java:94)
        at java.lang.Exception.<init>(Exception.java:42)
        at java.lang.RuntimeException.<init>(RuntimeException.java:47)
        at java.lang.IllegalArgumentException.<init>(IllegalArgumentException.java:43)
        at java.lang.NumberFormatException.<init>(NumberFormatException.java:43)
        at java.lang.Integer.parseInt(Integer.java:419)
        at java.lang.Integer.parseInt(Integer.java:468)
        at Donuts7.main(Donuts7.java:39)



 ****/
