/* Calculate.java provides a simple 4-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;public class Calculate extends Object{  static Screen theScreen = new Screen();  static Keyboard theKeyboard = new Keyboard();  static final String MENU = "\nPlease enter:\n" +                      	"\t+, to perform addition;\n" +	              		"\t-, to perform subtraction;\n" +                      	"\t*, to perform multiplication;\n" +                      	"\t/, to perform division;\n" +                      	"--> ";  public static void main(String args[])  {  	theScreen.println("\nWelcome to the 4-function calculator!\n" + MENU);  	char operation;	operation = theKeyboard.readChar();  	Assertion.check(operation == '+' || operation == '-' ||          		operation == '*' || operation == '/');	theScreen.print("\nNow enter your operands: ");	double op1, op2;	op1 = theKeyboard.readDouble();	op2 = theKeyboard.readDouble();	Assertion.check(operation != '/' || op2 != 0);	double result = apply(operation, op1, op2);	theScreen.println("\n" + op1 + operation + op2       + " = " + result);  }  // ... Replace this line with the definition of apply()}
