123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
-
- /**
- * 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 | exp | inverse |");
- System.out.println("cos | sine | tan | cos-1 | sin-1 | m+ | m- | MRC");
- System.out.println("log | ln | ex |");
- 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();
- // 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("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
-
- }
-
|