//
// ExceptionTest.java
// Demonstrates exception handling in Java
//
// Nadeem Abdul Hamid
// CSC 121 - Berry College
//

import java.io.*;

public class ExceptionTest 
{
    public static int quotient( int num, int denom ) 
    {
	return num / denom;
    }


    public static void main( String args[] ) 
    {
	System.out.println( "Welcome!" );

	boolean continueloop = true;  // loop will continue until valid input

	BufferedReader in             // keyboard input object
	    = new BufferedReader( new InputStreamReader( System.in ) );

	do 
        {
	    try {
		String n = in.readLine();
		String d = in.readLine();
		System.out.println( n + "/" + d );
		System.out.println( quotient( Integer.parseInt( n ), 
					      Integer.parseInt( d ) ) );
		System.out.println( "Thank you!" );
		continueloop = false;    // processing successful, stop loop
	    } // end try
	    catch ( NumberFormatException e ) {
		System.out.println( "Format error: please type integers." );
		e.printStackTrace();
	    } // end catch NumberFormatException
	    catch ( ArithmeticException e ) {
		System.out.println( "Division by zero attempted." );
	    } // end catch ArithmeticException
	    catch ( IOException e ) {
		System.out.println( "IO exception occurred: " + e );
	    } // end catch IOException
	} while ( continueloop );

	System.out.println( "Good bye!" );
	
    }
}