
/*

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 

 */

public class GotMilk2 {
	
	private int donutCount, milkCount;

	private double donutsPerGlass( ) {
		return( (double)donutCount/(double)milkCount ); 
		}

	private int prompt( String comment ) {

		System.out.println( comment );
		return( SavitchIn.readLineInt() );
		}
	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 ) {

		GotMilk2 milk = new GotMilk2( );
		milk.donutCount = milk.prompt( "How many donuts do we have? ");
		milk.milkCount  = milk.prompt( "How many glasses of milk? " );
		milk.print( );
		}
}
		
		

