/* Calculate2.java provides a simple 5-function calculator. * * Adapted by: Charles Hoot, for Hands On Java. * From: Joel Adams, for Hands On C++. * Completed by: * Date: * Purpose: * * Specification: * input(keyboard): a char, stored in operator; *                  two reals, stored in op1 and op2; * output(screen): the result of the expression (op1 operator op2). *****************************************************************/import ann.easyio.*;import hoj.Assertion;class Calculate2 extends Object{	static Screen theScreen = new Screen();	static Keyboard theKeyboard = new Keyboard();	static final String MENU = "\nPlease enter:\n" +                      	"\ta, to perform addition;\n" +	              		"\tb, to perform subtraction;\n" +                      	"\tc, to perform multiplication;\n" +                      	"\td, to perform division;\n" +                      	"\te, to perform exponentiation;\n" +                      	"--> ";	public static void main(String args[])	{		double op1 = 0.0, op2 = 0.0;		theScreen.println("\nWelcome to the 5-function calculator!\n");		char operation = getMenuChoice(MENU);		theScreen.print("\nNow enter your operands: ");		op1 = theKeyboard.readDouble();		op2 = theKeyboard.readDouble();		Assertion.check(operation != '/' || op2 != 0);		double result = apply(operation, op1, op2);		theScreen.println("\nThe result is " + result);	}		private static char getMenuChoice(String menu)	{		theScreen.print(menu);		char choice;		choice = theKeyboard.readChar();		return choice;	}	private static double apply(char operation, double op1, double op2)	{		switch (operation)		{			case 'a':				return op1 + op2;			case 'b':				return op1 - op2;			case 'c':				return op1 * op2;			case 'd':				return op1 / op2;			case 'e'://				return power(op1, (int) op2);			default:				theScreen.println("\nInvalid operation " + operation						+ " received by calculator!\n");		}	return 0.0;  }// ... replace this line with the definition of power() ...} // end of class
