MainApplication.java 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. public class MainApplication {
  2. public static void main(String[] args) {
  3. Console.println("Welcome to Vince and Ray's Calculator!");
  4. Double display = Console.getDoubleInput("Enter your first number: ");
  5. while(true){
  6. try{
  7. String operator = Console.getStringInput("Enter the operation you'd like to perform or type\n'help' to see a list of commands.");
  8. if(operator.equalsIgnoreCase("Add")){
  9. Integer entered = Console.getIntegerInput("Enter your second integer: ");
  10. CoreFunctions.add(display, entered);
  11. display = display + entered;
  12. }
  13. if(operator.equalsIgnoreCase("Subtract")){
  14. Integer entered = Console.getIntegerInput("Enter your second integer: ");
  15. CoreFunctions.subtract(display, entered);
  16. display = display - entered;
  17. }
  18. if(operator.equalsIgnoreCase("Multiply")){
  19. Integer entered = Console.getIntegerInput("Enter your second integer: ");
  20. CoreFunctions.multiply(display, entered);
  21. display = display * entered;
  22. }
  23. if(operator.equalsIgnoreCase("Divide")){
  24. Double entered = Console.getDoubleInput("Enter your second integer: ");
  25. if(entered != 0){
  26. CoreFunctions.divide(display, entered);
  27. display = display / entered;
  28. }else {
  29. System.out.println("Err");
  30. }
  31. }
  32. if(operator.equalsIgnoreCase("Exponent")){
  33. Double entered = Console.getDoubleInput("Enter your second integer: ");
  34. CoreFunctions.exp(display, entered);
  35. display = (double) Math.pow(display,entered);
  36. }
  37. if(operator.equalsIgnoreCase("squared")){
  38. ScientificFunctions.sqr(display);
  39. display = display*display;
  40. }
  41. if(operator.equalsIgnoreCase("square root")){
  42. ScientificFunctions.sqRoot(display);
  43. display = ((double)Math.sqrt(display));
  44. }
  45. if(operator.equalsIgnoreCase("Inverse Fraction")){
  46. ScientificFunctions.invFraction(display);
  47. display = 1/display;
  48. }
  49. if(operator.equalsIgnoreCase("Inverse Sign")){
  50. ScientificFunctions.invSign(display);
  51. display = -1/display;
  52. }
  53. if(operator.equalsIgnoreCase("sine")){
  54. ScientificFunctions.sin(display);
  55. display = (double)Math.sin(display);
  56. }
  57. if(operator.equalsIgnoreCase("cosine")){
  58. ScientificFunctions.cosine(display);
  59. display = (double)Math.cos(display);
  60. }
  61. if(operator.equalsIgnoreCase("tangent")){
  62. ScientificFunctions.tan(display);
  63. display = (double)Math.tan(display);
  64. }
  65. if(operator.equalsIgnoreCase("inverse tangent")){
  66. ScientificFunctions.atan(display);
  67. display = (double)Math.atan(display);
  68. }
  69. if(operator.equalsIgnoreCase("inverse sin")){
  70. ScientificFunctions.asin(display);
  71. display = (double)Math.asin(display);
  72. }
  73. if(operator.equalsIgnoreCase("inverse cosine")){
  74. ScientificFunctions.acosin(display);
  75. display = (double)Math.acos(display);
  76. }
  77. if(operator.equalsIgnoreCase("M+")){
  78. System.out.println("Memory Added");
  79. ScientificFunctions.memory=display;
  80. }
  81. if(operator.equalsIgnoreCase("MC")){
  82. System.out.println("Memory Cleared");
  83. ScientificFunctions.memory=0;
  84. }
  85. if(operator.equalsIgnoreCase("MRC")){
  86. System.out.println("Memory Recalled!");
  87. display = ScientificFunctions.memory;
  88. }
  89. if(operator.equalsIgnoreCase("clear")){
  90. System.out.print('\u000C');
  91. }
  92. if(operator.equalsIgnoreCase("clear dis")){
  93. System.out.print("Display Cleared!\n");
  94. display = (double) 0;
  95. }
  96. if(operator.equalsIgnoreCase("exit")){
  97. System.out.println("Thanks for using our Calculator!");
  98. break;
  99. }
  100. if(operator.equalsIgnoreCase("help")){
  101. System.out.println("You may Enter: \nOPERATORS\nAdd\nSubtract\nMultiply\nDivide\nExponent\nSquared\nSquare Root\nInverse Fraction\nInverse Sign\nSine\nCosine\nTangent\nInverse Tangent\nInverse Sine\nInverse Cosine\nInverse Tangent\n\nMEMORY FUNCTIONS\nM+ - Add to Memory\nMRC - Recall from Memory\nMC - Clear Memory\n\nDISPLAY MODE FUNCTIONS\nDec Mode - Display in Decimal Format\nHex Mode - Display in Hexadecimal Format\nBin Mode - Display in Binary Format\nOct Mode - Display in Octal Format\nToggle Display Mode - Chooses next display mode\nDeg Mode - Display Trig Functions in Degrees\nRad Mode - Display Trig Functions in Radians\nToggle Trig Mode - Chooses next trig display mode\n\nOTHER FUNCTIONS\nClear Display\nExit\nTemp Conversion - Convert Farenheit to Celcius, and vice versa.");
  102. }
  103. if(operator.equalsIgnoreCase("hex mode")){
  104. System.out.println("Hex Mode Activated");
  105. CoreFunctions.binMode = false;
  106. CoreFunctions.octMode = false;
  107. CoreFunctions.decMode = false;
  108. CoreFunctions.hexMode = true;
  109. }
  110. if(operator.equalsIgnoreCase("bin mode")){
  111. System.out.println("Binary Mode Activated");
  112. CoreFunctions.binMode = true;
  113. CoreFunctions.octMode = false;
  114. CoreFunctions.decMode = false;
  115. CoreFunctions.hexMode = false;
  116. }
  117. if(operator.equalsIgnoreCase("oct mode")){
  118. System.out.println("Octal Mode Activated");
  119. CoreFunctions.binMode = false;
  120. CoreFunctions.octMode = true;
  121. CoreFunctions.decMode = false;
  122. CoreFunctions.hexMode = false;
  123. }
  124. if(operator.equalsIgnoreCase("dec mode")){
  125. System.out.println("Decimal Mode Activated");
  126. CoreFunctions.binMode = false;
  127. CoreFunctions.octMode = false;
  128. CoreFunctions.decMode = true;
  129. CoreFunctions.hexMode = false;
  130. }
  131. if(operator.equalsIgnoreCase("Toggle Display Mode")){
  132. if(CoreFunctions.binMode == true){
  133. System.out.println("Octal Mode Activated!");
  134. CoreFunctions.binMode = false;
  135. CoreFunctions.octMode = true;
  136. CoreFunctions.decMode = false;
  137. CoreFunctions.hexMode = false;
  138. } else if(CoreFunctions.octMode == true){
  139. System.out.println("Decimal Mode Activated!");
  140. CoreFunctions.binMode = false;
  141. CoreFunctions.octMode = false;
  142. CoreFunctions.decMode = true;
  143. CoreFunctions.hexMode = false;
  144. }else if(CoreFunctions.decMode == true){
  145. System.out.println("Hexadecimal Mode Activated!");
  146. CoreFunctions.binMode = false;
  147. CoreFunctions.octMode = false;
  148. CoreFunctions.decMode = false;
  149. CoreFunctions.hexMode = true;
  150. }else if(CoreFunctions.hexMode == true) {
  151. System.out.println("Binary Mode Activated!");
  152. CoreFunctions.binMode = true;
  153. CoreFunctions.octMode = false;
  154. CoreFunctions.decMode = false;
  155. CoreFunctions.hexMode = false;
  156. }
  157. else {
  158. System.out.println("Err");
  159. }
  160. }
  161. if(operator.equalsIgnoreCase("deg mode")){
  162. System.out.println("Degree Mode Activated");
  163. ScientificFunctions.degMode = true;
  164. ScientificFunctions.radMode = false;
  165. }
  166. if(operator.equalsIgnoreCase("rad mode")){
  167. System.out.println("Radian Mode Activated");
  168. ScientificFunctions.degMode = false;
  169. ScientificFunctions.radMode = true;
  170. }
  171. if(operator.equalsIgnoreCase("Toggle Trig Mode")){
  172. if(ScientificFunctions.degMode == true){
  173. System.out.println("Radian Mode Activated!");
  174. ScientificFunctions.degMode = false;
  175. ScientificFunctions.radMode = true;
  176. } else if(ScientificFunctions.radMode == true){
  177. System.out.println("Degree Mode Activated!");
  178. ScientificFunctions.degMode = true;
  179. ScientificFunctions.radMode = false;
  180. }
  181. }
  182. if(operator.equalsIgnoreCase("Temp Conversion")){
  183. String conversion = Console.getStringInput("Enter 'F' to convert Farenheit to Celsius, Enter 'C' to convert Celcius to Farenheit");
  184. if(conversion.equalsIgnoreCase("f")){
  185. ScientificFunctions.fToC(display);
  186. } else if (conversion.equalsIgnoreCase("c")){
  187. ScientificFunctions.cToF(display);
  188. }
  189. }
  190. }catch(Exception e){
  191. System.err.println(e);
  192. System.err.println("System Error: Try again");
  193. continue;
  194. }
  195. }
  196. }
  197. }
  198. //Integer i = Console.getIntegerInput("Enter an integer");
  199. //Double d = Console.getDoubleInput("Enter a double.");