123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /**
  2. * Write a description of class Cal here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. import java.io.IOException;
  8. import java.util.Scanner;
  9. import java.util.*;
  10. public class Cal{
  11. public static void main (String[]args){
  12. // instance variables - replace the example below with your own
  13. Scanner scan = new Scanner(System.in);
  14. double calcValue1;
  15. double calcValue2;
  16. double addTwoNumbers;
  17. double getCalcValue;
  18. int options = 0;
  19. double answer;
  20. double sum;
  21. boolean off = false;
  22. boolean on = true;
  23. int num1 =0;
  24. int num2 =0;
  25. System.out.print("Let's crunch some numbers");
  26. while (on){
  27. System.out.println("Please enter the number of what you want to do");
  28. System.out.println("1. Add ");
  29. System.out.println("2. Substract");
  30. System.out.println("3. Multiply ");
  31. System.out.println("4. Division");
  32. System.out.println("5. Modulus ");
  33. System.out.println("6. Square Root");
  34. System.out.println("7. Avg");
  35. System.out.println("8. Exp");
  36. System.out.println("9. Mode");
  37. System.out.println("10. Max");
  38. System.out.println("11. Min");
  39. System.out.println("12. Abs");
  40. System.out.println("13. Round");
  41. System.out.println("14. Sin");
  42. System.out.println("15. Cos");
  43. System.out.println("16. tan");
  44. System.out.println("17. Quit");
  45. scan.hasNextInt();
  46. options = scan.nextInt();
  47. try{
  48. switch (options){
  49. case 1: //Sum
  50. //System.out.print('\u000C');
  51. System.out.println("Enter Number1 ");
  52. num1= scan.nextInt();
  53. System.out.println("Enter Number2 ");
  54. num2 = scan.nextInt();
  55. answer=Math_methods.add(num1,num2);
  56. System.out.println(answer);
  57. break;
  58. case 2: //difference:
  59. //System.out.print('\u000C');
  60. System.out.println("Enter Number1 ");
  61. num1= scan.nextInt();
  62. System.out.println("Enter Number2 ");
  63. num2 = scan.nextInt();
  64. answer = Math_methods.minus(num1,num2);
  65. System.out.println(answer);
  66. break;
  67. case 3: // multiply:
  68. //System.out.print('\u000C');
  69. System.out.println("Enter Number1 ");
  70. num1= scan.nextInt();
  71. System.out.println("Enter Number2 ");
  72. num2 = scan.nextInt();
  73. answer = Math_methods.mult(num1,num2);
  74. System.out.println(answer);
  75. break;
  76. case 4: //divide:
  77. //System.out.print('\u000C');
  78. System.out.println("Enter Number1 ");
  79. num1= scan.nextInt();
  80. System.out.println("Enter Number2 ");
  81. num2 = scan.nextInt();
  82. answer = Math_methods.div(num1,num2);
  83. System.out.println(answer);
  84. break;
  85. case 5: //modulus:
  86. //System.out.print('\u000C');
  87. System.out.println("Enter Number1 ");
  88. num1= scan.nextInt();
  89. System.out.println("Enter Number2 ");
  90. num2 = scan.nextInt();
  91. answer = Math_methods.mod(num1,num2);
  92. System.out.println(answer);
  93. break;
  94. case 6: //squareRoot:
  95. //System.out.print('\u000C');
  96. System.out.println("Enter Number1 ");
  97. num1= scan.nextInt();
  98. answer = Math_methods.sqrt(num1);
  99. System.out.println("Enter Number2 ");
  100. num2 = scan.nextInt();
  101. answer = Math_methods.sqrt(num1);
  102. System.out.println(answer);
  103. break;
  104. case 7: //Average:
  105. //System.out.print('\u000C');
  106. System.out.println("Enter Number1 ");
  107. num1= scan.nextInt();
  108. System.out.println("Enter Number2 ");
  109. num2 = scan.nextInt();
  110. answer = Math_methods.ave(num1,num2);
  111. System.out.println(answer);
  112. break;
  113. case 8: //Exponent:
  114. //System.out.print('\u000C');
  115. System.out.println("Enter Number1 ");
  116. num1= scan.nextInt();
  117. System.out.println("Enter Number2 ");
  118. num2 = scan.nextInt();
  119. answer = Math_methods.exp(num1,num2);
  120. System.out.println(answer);
  121. break;
  122. case 9: //Mod:
  123. //System.out.print('\u000C');
  124. System.out.println("Enter Number1 ");
  125. num1= scan.nextInt();
  126. System.out.println("Enter Number2 ");
  127. num2 = scan.nextInt();
  128. answer = Math_methods.mod(num1,num2);
  129. System.out.println(answer);
  130. break;
  131. case 10:
  132. System.out.println("Enter Number1 ");
  133. num1= scan.nextInt();
  134. System.out.println("Enter Number2 ");
  135. num2 = scan.nextInt();
  136. answer = Math_methods.max(num1,num2);
  137. System.out.println(answer);
  138. break;
  139. case 11: //Minimum:
  140. System.out.println("Enter Number1 ");
  141. num1= scan.nextInt();
  142. System.out.println("Enter Number2 ");
  143. num2 = scan.nextInt();
  144. answer = Math_methods.min(num1,num2);
  145. System.out.println(answer);
  146. break;
  147. case 12: //Absolute value:
  148. //System.out.print('\u000C');
  149. System.out.println("Enter Number1 ");
  150. num1= scan.nextInt();
  151. answer = Math_methods.abs(num1);
  152. System.out.println(answer);
  153. break;
  154. case 13:
  155. System.out.println("Enter Number1 ");
  156. num1= scan.nextInt();
  157. answer = Math_methods.round(num1);
  158. System.out.println(answer);
  159. break;
  160. case 14:
  161. System.out.println("Enter Number1 ");
  162. num1= scan.nextInt();
  163. answer = Math_methods.sin(num1);
  164. System.out.println(answer);
  165. break;
  166. case 15:
  167. System.out.println("Enter Number1 ");
  168. num1= scan.nextInt();
  169. answer = Math_methods.cos(num1);
  170. System.out.println(answer);
  171. break;
  172. case 16:
  173. System.out.println("Enter Number1 ");
  174. num1= scan.nextInt();
  175. answer = Math_methods.tan(num1);
  176. System.out.println(answer);
  177. break;
  178. case 17:
  179. System.exit(0);
  180. break;
  181. default:
  182. System.out.println("Hello");
  183. System.out.print('\u000C');
  184. }
  185. }
  186. catch(NumberFormatException e){
  187. //catch(Exception e){
  188. System.out.printf("Wrong number or not enough numbers");
  189. }
  190. /* while(options == 0){
  191. break;
  192. }*/
  193. }
  194. }
  195. /*catch(IOException e){
  196. System.out.println(error);
  197. abc.displayErrorMessage("Please Enter 2 digit");
  198. }
  199. /*
  200. public void addNum2(int Number1, int Number2){
  201. calcValue1 = Number1 + Number2;
  202. }
  203. public int getCalcValue(){
  204. return calculationValue;
  205. */
  206. }