
/*

inputs number of donuts, and glasses of milk
program, prints out number of donuts,
glasses of milk and donuts per glass,

Program  raises exception and handles it if no milk exists 

Program also raises exception on any number less than 1

 */

public class GotMilk3 {
	
	private int donutCount, milkCount;

	private double donutsPerGlass( ) {
		return( (double)donutCount/(double)milkCount ); 
		}

	private int prompt( String comment ) {

		System.out.println( comment );
		int temp = SavitchIn.readLineInt();
		try {
			if( temp <= 1 ) 
				throw new Exception( "Exception Less than 1 " );
                      } catch( Exception e ) {
			System.out.println( e.getMessage() );
			System.out.println( "Need number >= 1" );
			System.exit( 1 );  // 0 Normal termination
		} //End catch
                return temp;
		}
	
	private void print( ) {

		// Create a block try - see if you can have donuts and milk
		try {
			if( milkCount < 1 )
				throw new Exception( "Exception: No Milk!" );
			
			System.out.println( donutCount + " donuts " +
			"and " + milkCount + " glasses of milk." );
			System.out.println( "You have " + donutsPerGlass() +
			" donuts for each glass of milk." );
			
		} catch( Exception e ) {
			//Call getMessage of predefined class Exception
			System.out.println( e.getMessage() );
			System.out.println( "Go Buy some milk." );
		} 
		} // End of void print( )

	public static void main( String[] args ) {

		GotMilk3 milk = new GotMilk3( );
		milk.donutCount = milk.prompt( "How many donuts do we have? ");
		milk.milkCount  = milk.prompt( "How many glasses of milk? " );
		milk.print( );
		}
}
		
		

