Calculations.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import java.util.ArrayList;
  2. public class Calculations
  3. {
  4. public static Console console = new Console();
  5. public static ArrayList<String> library = new ArrayList<String>();
  6. public Calculations(){
  7. library.add("multiply");
  8. library.add("divide");
  9. library.add("subtract");
  10. library.add("add");
  11. library.add("COS");
  12. library.add("SIN");
  13. library.add("TAN");
  14. library.add("invertS");
  15. library.add("invertN");
  16. library.add("factorial");
  17. library.add("switchunit");
  18. library.add("clear");
  19. library.add("storeM");
  20. library.add("resetM");
  21. library.add("recallM");
  22. library.add("displayM");
  23. }
  24. public static void getCommand(String userInput)
  25. {
  26. boolean foundCommand = false;
  27. String command = "";
  28. String result = "";
  29. String[] inputArr = userInput.split(" ");
  30. for(int i = 0; i < library.size(); i ++)
  31. {
  32. String currCommand = library.get(i);
  33. if(currCommand.equalsIgnoreCase(inputArr[0]))
  34. {
  35. command = currCommand;
  36. foundCommand = true;
  37. break;
  38. }
  39. }
  40. switch(command)
  41. {
  42. case "multiply":
  43. result = Multiply(userInput);
  44. break;
  45. case "divide":
  46. result = Divide(userInput);
  47. break;
  48. case "add":
  49. result = Add(userInput);
  50. break;
  51. case "subtract":
  52. result = Subtract(userInput);
  53. break;
  54. case "invertS":
  55. result = InvertSign(userInput);
  56. break;
  57. case "invertN":
  58. result = InvertNumber(userInput);
  59. break;
  60. case "clear":
  61. Clear();
  62. break;
  63. }
  64. System.out.println(result);
  65. //return result;
  66. }
  67. public static ArrayList<Double> getNumbers(String userInput){
  68. ArrayList<Double> results = new ArrayList<Double>();
  69. //takes in a string
  70. //finds the first occurence of a number
  71. //store it as a double ( left )
  72. //add this to the arraylist
  73. //find the second occurence of a number
  74. //store it as a double (right)
  75. //add this to the array list
  76. //if the size of the arraylist is 2
  77. //return the array list
  78. //else return null
  79. return results;
  80. }
  81. public static String Multiply(String userInput)
  82. {
  83. //perform the operation
  84. //convert to string
  85. //return string
  86. return null;
  87. }
  88. public static String Divide(String userInput)
  89. {
  90. //perform the operation
  91. //convert to string
  92. //return string
  93. return null;
  94. }
  95. public static String Add(String userInput)
  96. {
  97. //perform the operation
  98. //convert to string
  99. //return string
  100. return null;
  101. }
  102. public static String Subtract(String userInput)
  103. {
  104. //perform the operation
  105. //convert to string
  106. //return string
  107. return null;
  108. }
  109. public static String InvertSign(String userInput)
  110. {
  111. //perform the operation
  112. //convert to string
  113. //return string
  114. return null;
  115. }
  116. public static String InvertNumber(String userInput)
  117. {
  118. //perform the operation
  119. //convert to string
  120. //return string
  121. return null;
  122. }
  123. public static void Clear()
  124. {
  125. //reset the default value to 0
  126. }
  127. }