import tio.*;

/**
 * The class <code>calc</code> is a simple
 * class to implement a four-function calculator 
 * It uses nothing special
 * Makes use of package tio
 *
 * @author K Becker
 * @version 1.0
 */

public class calc
{
    /*********************************************************/
    /**
     * read a number from stdin -
     * seperated from next thing by at least one blank
     * 
     * @return integer read from console
     */
    private static int getNum() {
	
	return Console.in.readInt();	
	
    } /* end getNum */
    
    
    /*********************************************************/
    /**
     * Main Program.
     * Turns your powerful, expensive computer in to something less
     * useful than a $1.98 calculator.
     * 
     */
    public static void main(String[] args)
    {        
	int first = 0;
	int result = 0;
	int num = 0;
	boolean OK = true;
	boolean done = false;
	char op = ' ';
	char ans = 'n';


	System.out.print("Calculator:\n");
	System.out.print("\n");
	System.out.print("This program turns your powerful, expensive computer\n");
	System.out.print("into something less useful than a $1.99 calculator.\n");
	System.out.print("Cool, huh.\n");
	System.out.print("\n");
	System.out.print("Enter an integer, then an operator, then another integer\n");
	System.out.print("followed by <RETURN>.\n");
	System.out.print("\n");
	System.out.print("Allowable operators are: + - * /\n");
	System.out.print("\n");
	
	/* begin */
        while (!done)
	    {
                System.out.print(">> ");
                first = result = getNum();
		
                /* skip blanks */
                op = ' ';
                while (op == ' ') 
		    op = (char)Console.in.readChar();
		
                num = getNum();
		Console.in.readLine();
		
                switch (op) {
		    case '+' : result += num;
		    break;
		    case '-' : result -= num;
		    break;
		    case '*' : result *= num;
		    break;
		    case '/' : result /= num;
		    break;
		default:
                } /* case */
		
                System.out.print("\n");
                System.out.print(first);
		System.out.print(" ");
		System.out.print(op);
		System.out.print(" ");
		System.out.print(num);
		System.out.print(" = ");
		System.out.print(result);
                System.out.print("\n");
                System.out.print("Another? ");
                ans = (char)Console.in.readChar();
		
                done = ((ans != 'y') && (ans != 'Y'));
		
	    } /* while not done */
	
	}

}
