1   // joi/2/arithmetic/IntArithmetic.java                         
2   //                                                            
3   //                                                            
4   // Copyright 2003 Bill Campbell and Ethan Bolker                         
5                                                               
6   /**
7    * Interactive play with integer arithmetic in Java,
8    * using a Terminal for input and output.
9    */
10  
11  public class IntArithmetic
12  {
13      private static Terminal terminal = new Terminal();
14  
15      /**
16       * main prompts for pairs of numbers to add and to divide
17       * until the bored user decides to quit.
18       */
19  
20      public static void main(String[] args)
21      {
22          while ( terminal.readYesOrNo( "Try int z = x + y ? " ) ) {
23              tryIntegerAddition( );
24          }
25          while ( terminal.readYesOrNo( "Try int z = x / y ? " ) ) {
26              tryIntegerDivision();
27          }
28      }
29  
30      // Prompt for two ints and add them.
31  
32      private static void tryIntegerAddition()
33      {
34          int x = terminal.readInt( "x = ");
35          int y = terminal.readInt( "y = " );
36          terminal.println( "z = " + (x+y) );
37      }
38      
39      // Prompt for two ints and divide the first by
40      // the second.
41  
42      private static void tryIntegerDivision()
43      {
44          int x = terminal.readInt( "x = ");
45          int y = terminal.readInt( "y = " );
46          terminal.println( "z = " + (x/y) );
47      }
48  }
49