import java.util.*; import java.io.*; /**  * Write a description of class main here.  */ public class main { public static void main(String args[]) // This is the main method. // It takes a string array(=args) (not used) // and returns nothing (void). // A static function called 'main' with String array is needed in order // to run as a commandline program under 'java' etc. Since this is is // static, no instance variables (fields) or constructor methods are used. { String Equation = ""; InputStreamReader isr = new InputStreamReader(System.in); BufferedReader stdin = new BufferedReader(isr); while (true) { // This means that the loop continues forever. // Normally this would cause the while loop to go on forever, which would be bad... // However, this loop is broken when the user types 'end'. try { System.out.println("--------------------------------------"); System.out.print("Please enter an equation or 'end' to exit this program: "); Equation = stdin.readLine(); // This reads all the lines that the user inputs if ( Equation.compareTo("end") == 0 ) { // apparently the compareTo method should be used to compare strings. break; // break escapes from the while{} loop, hence ending the program. } double answer = Evaluate(Equation); // calls the Evaluate method to solve the equation System.out.println("the answer is "+answer); } catch (Exception exp) { System.out.println("Error"); } } System.out.println("thankyou for using the java calculator."); } /**      * This is a method that evaluates the equation.      */ public static double Evaluate(String Equation) { // double means a number that can take numbers of any length // and also floating point numbers char charArray[]; charArray = Equation.toCharArray(); // java's method to convert a String to an array of characters int EquationLength = Equation.length(); // takes the length of an equation into account boolean done[] = new boolean[100]; // boolean array which sees if these parts have been calculated or not char operators[] = new char[100]; // character array with operators used String parts[] = new String[100]; // String array with parts of the equation Arrays.fill(parts,""); // fill parts with empty strings -- for some reason java seems // to create String arrays with null (0) characters. int countParts=0; // for loop starts with charPosition=0, adds 1 to charPosition each loop, // while charPosition is still less than EquationLength. (1 loop for each character) for(int charPosition=0; charPosition