Console.java 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import java.util.Scanner;
  2. /**
  3. * Created by leon on 2/9/18.
  4. */
  5. public class Console {
  6. public void runCommandLoop() {
  7. Scanner input = new Scanner(System.in);
  8. //String a = input.nextLine();
  9. //String b = input.nextLine();
  10. // Calculator calc = new ....
  11. System.out.println("Gimme some math to do!");
  12. System.out.println("Enter a command or \"HELP\" for help");
  13. while (true) {
  14. try{
  15. double value = 0;
  16. String command = input.nextLine();
  17. if (command.equalsIgnoreCase("exit")) {
  18. System.out.println("Thanks for calculating with us!");
  19. break;
  20. }
  21. else if (command.equalsIgnoreCase("help")) {
  22. System.out.println(Help.text());
  23. }
  24. else if (command.equalsIgnoreCase("dec")) {
  25. System.out.println("Now working in DECIMAL MODE");
  26. }
  27. else if (command.equalsIgnoreCase("bin")) {
  28. System.out.println("Now working in BINARY MODE");
  29. }
  30. else if (command.equalsIgnoreCase("hex")) {
  31. System.out.println("Now working in HEXIDECIMAL MODE");
  32. }
  33. else if (command.equalsIgnoreCase("Oct")) {
  34. System.out.println("Now working in OCTAL MODE");
  35. }
  36. else if (command.equalsIgnoreCase("rad")) {
  37. System.out.println("RADIANS");
  38. }
  39. else if (command.equalsIgnoreCase("deg")) {
  40. System.out.println("DEGREES");
  41. }
  42. else if (command.equalsIgnoreCase("units next")) {
  43. //rotate units to next
  44. }
  45. else if (command.equalsIgnoreCase("add")) {
  46. System.out.println("Please input first number");
  47. double i = input.nextDouble();
  48. System.out.println("Please input second number");
  49. double j = input.nextDouble();
  50. value = Functions.add(i, j);
  51. System.out.println(value);
  52. System.out.println("Enter a command.");
  53. }
  54. else if (command.equalsIgnoreCase("subtract")) {
  55. System.out.println("Please input first number");
  56. double i = input.nextDouble();
  57. System.out.println("Please input second number");
  58. double j = input.nextDouble();
  59. value = Functions.subtract(i, j);
  60. System.out.println(value);
  61. System.out.println("Enter a command.");
  62. }
  63. else if (command.equalsIgnoreCase("multiply")){
  64. System.out.println("Please input first number");
  65. double i = input.nextDouble();
  66. System.out.println("Please input second number");
  67. double j = input.nextDouble();
  68. //return
  69. System.out.println(Functions.multiply(i, j));
  70. System.out.println("Enter a command.");
  71. }
  72. else if (command.equalsIgnoreCase("divide")){
  73. System.out.println("Please input first number");
  74. double i = input.nextDouble();
  75. System.out.println("Please input second number");
  76. double j = input.nextDouble();
  77. System.out.println(Functions.divide(i,j));
  78. System.out.println("Enter a command.");
  79. }
  80. else if (command.equalsIgnoreCase("square")) {
  81. System.out.println("Please input a number");
  82. double i = input.nextDouble();
  83. System.out.println(Functions.square(i));
  84. System.out.println("Enter a command.");
  85. }
  86. else if (command.equalsIgnoreCase("root")){
  87. System.out.println("Please input a number");
  88. double i = input.nextDouble();
  89. //return
  90. System.out.println(Functions.squareRoot(i));
  91. System.out.println("Enter a command.");
  92. }
  93. else if (command.equalsIgnoreCase("exponent")){
  94. System.out.println("Please input first number");
  95. double i = input.nextDouble();
  96. System.out.println("Please input second number");
  97. double j = input.nextDouble();
  98. //return
  99. System.out.println(Functions.exponent(i, j));
  100. System.out.println("Enter a command.");
  101. }
  102. else if (command.equalsIgnoreCase("inverse")){
  103. System.out.println("Please input a number");
  104. double i = input.nextDouble();
  105. //return
  106. System.out.println(Functions.inverse(i));
  107. System.out.println("Enter a command.");
  108. }
  109. else if (command.equalsIgnoreCase("invert")){
  110. System.out.println("Please input a number");
  111. double i = input.nextDouble();
  112. //return
  113. System.out.println(Functions.invertSign(i));
  114. System.out.println("Enter a command.");
  115. }
  116. else if (command.equalsIgnoreCase("sin")){
  117. System.out.println("Please input a number");
  118. double i = input.nextDouble();
  119. //return
  120. System.out.println(Functions.sin(i));
  121. System.out.println("Enter a command.");
  122. }
  123. else if (command.equalsIgnoreCase("cos")) {
  124. System.out.println("Please input a number");
  125. double i = input.nextDouble();
  126. //return
  127. System.out.println(Functions.cos(i));
  128. System.out.println("Enter a command.");
  129. }
  130. else if (command.equalsIgnoreCase("tan")) {
  131. System.out.println("Please input a number");
  132. double i = input.nextDouble();
  133. //return
  134. System.out.println(Functions.tan(i));
  135. System.out.println("Enter a command.");
  136. }
  137. else if (command.equalsIgnoreCase("cot")) {
  138. System.out.println("Please input a number");
  139. double i = input.nextDouble();
  140. //return
  141. System.out.println(Functions.cot(i));
  142. System.out.println("Enter a command.");
  143. }
  144. else if (command.equalsIgnoreCase("sec")){
  145. System.out.println("Please input a number");
  146. double i = input.nextDouble();
  147. //return
  148. System.out.println(Functions.sec(i));
  149. System.out.println("Enter a command.");
  150. }
  151. else if (command.equalsIgnoreCase("cos")) {
  152. System.out.println("Please input a number");
  153. double i = input.nextDouble();
  154. //return
  155. System.out.println(Functions.csc(i));
  156. System.out.println("Enter a command.");
  157. }
  158. else if (command.equalsIgnoreCase("arcsin")){
  159. System.out.println("Please input a number");
  160. double i = input.nextDouble();
  161. //return
  162. System.out.println(Functions.arcsin(i));
  163. System.out.println("Enter a command.");
  164. }
  165. else if (command.equalsIgnoreCase("arccos")){
  166. System.out.println("Please input a number");
  167. double i = input.nextDouble();
  168. //return
  169. System.out.println(Functions.arccos(i));
  170. System.out.println("Enter a command.");
  171. }
  172. else if (command.equalsIgnoreCase("arctan")){
  173. System.out.println("Please input a number");
  174. double i = input.nextDouble();
  175. //return
  176. System.out.println(Functions.arctan(i));
  177. System.out.println("Enter a command.");
  178. }
  179. else if (command.equalsIgnoreCase("addMem")) {
  180. System.out.println("Adding to memory");
  181. double i = 0;
  182. i = Functions.memPlus(i);
  183. System.out.println(Functions.memPlus(i));
  184. System.out.println("Enter a command.");
  185. }
  186. else if(command.equalsIgnoreCase("clearMem")) {
  187. System.out.println("Clearing memory");
  188. double i = 0;
  189. System.out.println("Memory cleared");
  190. System.out.println("Enter a command.");
  191. }
  192. else if (command.equalsIgnoreCase("recall")) {
  193. System.out.println(Functions.recall());
  194. System.out.println("Enter a command.");
  195. }
  196. else if(command.equalsIgnoreCase("convert")){
  197. double convert = input.nextDouble();
  198. Conversion.switchDisplay(convert);
  199. System.out.println("Enter a command.");
  200. }
  201. }
  202. catch(Exception e){
  203. System.err.print("error!");
  204. continue;
  205. }
  206. }
  207. }
  208. public static void main(String[] args){
  209. /*Conversion conv = new Conversion();
  210. Functions c = new Functions();
  211. c.functions();
  212. Help h = new Help();
  213. h.help();*/
  214. }
  215. }