
/*
 * program to demonstrate a more complicated "switch" statement
 */

import java.lancs.* ;

public class Chapter4n1d
    {
    /*
     * main
     */

    public static void main(String[] args) throws Exception
	{
	BasicIo.prompt("type the first operand: ") ;
	int operand1 = BasicIo.readInteger() ;
	BasicIo.prompt("type an operator (+, -, * or /): ") ;
	char operator = BasicIo.readCharacter() ;
	BasicIo.prompt("type the second operand: ") ;
	int operand2 = BasicIo.readInteger() ;
	int result = 0 ;
	switch (operator)
	    {
	    case '+' :
		result = operand1 + operand2 ;
		break;
	    case '-' :
		result = operand1 - operand2 ;
		break;
	    case '*' :
		result = operand1 * operand2 ;
		break;
	    case '/' :
		result = operand1 / operand2 ;
		break;
	    default :
		System.out.print("illegal operator") ;
	     } ;
	System.out.println("the result is " + result) ;
	} // end of method main
    } // end of class Chapter4n1d

