//********** //SimpleCalculator.java //John Purcell //CS 160: HW5 //October 22, 2008 //This program reads user input and returns the operation while checking //for "user error" to make sure inputs are within parameters //********** import java.util.Scanner; public class SimpleCalculator { public static void main (String[] args){ System.out.println("Type and equation"); System.out.println("Example: 3 * 4 (include spaces)"); Scanner S = new Scanner(System.in); double a=0; double b=0; double r=0; double var=.000001; //though the case may be handled if the variables are not assigned, by initializing them before //any other assignment, the program will compile without error. if (S.hasNextDouble()){; a = S.nextDouble(); } else{ System.out.println("operand needs to be a number"); System.exit(1); } String O = S.next(); //the string variable just needs to be assigned. By doing the order //the proper inputs are received. if (S.hasNextDouble()){ b = S.nextDouble(); } else{ System.out.println("operand needs to be a number"); System.exit(1); //Both (a) and (b) are checked by the hasNextDouble() checker. By using the widest //checker, they only need to be passed once. The INT or DOUBLE check is done later. } if (O.equals("+")){ r=(a-(int)a)-(b-(int)b); //the (r) equation checks whether the variables are both INT. If r != 0 (in this case (var) //to make sure small numbers are handled as well) then the program will pass the numbers as double. if (r