/** * Write a description of class Operations here. * * @author (your name) * @version (a version number or a date) */ import java.util.Scanner; public class Operations { /** * prompting a user for a command solving for that command * */ public static void printHelp(){ System.out.println("\n? | + | - | * | / |"); System.out.println("^ | sqrt | inverse |"); System.out.println("cos | sine | tan | cos-1 | sin-1 | m+ | m- | MRC"); System.out.println("log | ln | ex |"); System.out.println("To exit the program enter exit"); System.out.println("to clear display enter clrDisplay\n"); } public static double runCommand() { // put your code here Scanner input = new Scanner(System.in); double result = 0.0; //String userInput = scanner.nextLine(); scienticFunctions ScientificFunctions = new scienticFunctions(); Memory memory = new Memory(); DiplayMode displayMode = new DiplayMode(); bonusFunctions bonusFunctions = new bonusFunctions(); calculatorCoreFunctions calculatorCoreFunctions = new calculatorCoreFunctions(); // Calculator calc = new .... while (true) { System.out.print("Enter a command: "); String command = input.next(); if (command.equalsIgnoreCase("exit")) { System.out.print("Thanks for calculating with us!"); break; } else if (command.equalsIgnoreCase("+")){ if (result != 0){ double numInput = Console.getDoubleInput("Enter number"); result = calculatorCoreFunctions.add(result, numInput); } else{ double firstNumber = Console.getDoubleInput("Enter first number"); double secondNumber = Console.getDoubleInput("Enter second number"); result = calculatorCoreFunctions.add(firstNumber, secondNumber); } Console.printResult(result); } else if (command.equalsIgnoreCase("-")){ if (result != 0){ double numInput = Console.getDoubleInput("Enter number"); result = calculatorCoreFunctions.subtract(result, numInput); } else{ double firstNumber = Console.getDoubleInput("Enter first number"); double secondNumber = Console.getDoubleInput("Enter second number"); result = calculatorCoreFunctions.subtract(firstNumber, secondNumber);; } Console.printResult(result); } else if (command.equalsIgnoreCase("*")){ if (result != 0){ double numInput = Console.getDoubleInput("Enter number"); result = calculatorCoreFunctions.multiply(result, numInput); } else{ double firstNumber = Console.getDoubleInput("Enter first number"); double secondNumber = Console.getDoubleInput("Enter second number"); result = calculatorCoreFunctions.multiply(firstNumber, secondNumber);; } Console.printResult(result); } else if (command.equalsIgnoreCase("/")){ if (result != 0){ double numInput = Console.getDoubleInput("Enter number"); result = calculatorCoreFunctions.divide(result, numInput); } else{ double firstNumber = Console.getDoubleInput("Enter first number"); double secondNumber = Console.getDoubleInput("Enter second number"); result = calculatorCoreFunctions.divide(firstNumber, secondNumber);; } Console.printResult(result); } else if (command.equalsIgnoreCase("^")){ if (result != 0){ double numInput = Console.getDoubleInput("Enter number"); result = calculatorCoreFunctions.exponent(result, numInput); } else{ double firstNumber = Console.getDoubleInput("Enter first number"); double secondNumber = Console.getDoubleInput("Enter second number"); result = calculatorCoreFunctions.exponent(firstNumber, secondNumber);; } Console.printResult(result); } else if (command.equalsIgnoreCase("sqrt")) { if (result != 0){ result = calculatorCoreFunctions.sqrt(result); } else{ result = calculatorCoreFunctions.sqrt(Console.getDoubleInput("Enter number")); } Console.printResult(result); } else if (command.equalsIgnoreCase("inverse")) { if (result != 0){ result = calculatorCoreFunctions.inverse(result); } else{ result = calculatorCoreFunctions.inverse(Console.getDoubleInput("Enter number")); } Console.printResult(result); } else if (command.equalsIgnoreCase("sine")) { if (result != 0){ result = ScientificFunctions.sine(result); } else{ result = ScientificFunctions.sine(Console.getDoubleInput("Enter number")); } Console.printResult(result); } else if (command.equalsIgnoreCase("cos")) { if (result != 0){ result = ScientificFunctions.cosine(result); } else{ result = ScientificFunctions.cosine(Console.getDoubleInput("Enter number")); } Console.printResult(result); } else if (command.equalsIgnoreCase("tan")) { if (result != 0){ result = ScientificFunctions.tangent(result); } else{ result = ScientificFunctions.tangent(Console.getDoubleInput("Enter number")); } Console.printResult(result); } else if (command.equalsIgnoreCase("cos-1")) { if (result != 0){ result = ScientificFunctions.inverseCosine(result); } else{ result = ScientificFunctions.inverseCosine(Console.getDoubleInput("Enter number")); } Console.printResult(result); } else if (command.equalsIgnoreCase("sin-1")) { if (result != 0){ result = ScientificFunctions.inverseSine(result); } else{ result = ScientificFunctions.inverseSine(Console.getDoubleInput("Enter number")); } Console.printResult(result); } else if (command.equalsIgnoreCase("tan-1")) { if (result != 0){ result = ScientificFunctions.inverseTangent(result); } else{ result = ScientificFunctions.inverseTangent(Console.getDoubleInput("Enter number")); } Console.printResult(result); } else if(command.equalsIgnoreCase("M+")){ memory.storeInMemory(result); Console.printResult(result); } else if (command.equalsIgnoreCase("M-")){ Console.printResult(memory.clearMemory()); } else if (command.equalsIgnoreCase("MRC")){ Console.printResult(memory.retrieveFromMemory()); } else if (command.equalsIgnoreCase("switchmode")){ displayMode.setResult(result); String mode = displayMode.enterMode(); //System.out.println(mode); displayMode.switchDisplayMode(mode); } else if (command.equalsIgnoreCase("log")){ Console.printResult(bonusFunctions.LogBaseTenOfAnumber(result)); } else if (command.equalsIgnoreCase("ln")){ Console.printResult(bonusFunctions.naturalLogLn(result)); } else if (command.equalsIgnoreCase("ex")){ Console.printResult(bonusFunctions.exponential(result)); } else if(command.equalsIgnoreCase("?")){ printHelp(); } else if(command.equalsIgnoreCase("clrDisplay")){ result = 0.0; } else{ Console.println("Invalid command please press ? for help"); } //firstNumber = result; // and on and on } return result; } //Add CommentCollapse  }