fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9. public static Scanner input = new Scanner(System.in);
  10. public static double placeHolder;
  11.  
  12. public static void clear() {
  13. placeHolder = 0.0;
  14. System.out.println("Save has been deleted, Screen has been cleared.");
  15. }
  16.  
  17. public static void end() {
  18. System.out.println("Program ended..");
  19. input.close();
  20. System.exit(0);
  21. }
  22.  
  23. public static void save(double initValue) {
  24. System.out.println("Number saved!");
  25. placeHolder = initValue;
  26. }
  27.  
  28. public static void recall() {
  29. if (placeHolder != 0) {
  30. System.out.println("Memory Place Holder Set To: " + placeHolder);
  31. } else {
  32. System.out.println("There is no data saved.");
  33. }
  34. }
  35.  
  36. public static void commands() {
  37. System.out.println("e = end | c = clear | m = save | r = recall | o = continue");
  38. String command = input.next();
  39. if (command.equals("e")) {
  40. end();
  41. } else if (command.equals("c")) {
  42. clear();
  43. } else if (command.equals("r")) {
  44. recall();
  45. }
  46.  
  47. }
  48.  
  49. public static void main(String[] args) {
  50. boolean loop = true;
  51. while (loop == true) {
  52. commands();
  53. System.out.println("Please enter what you would like to do: (+,-,*,/,%)");
  54. String function = input.next();
  55. System.out.println("Enter the first number to be calucalted (If dividing, this is the numerator):");
  56. double n1 = input.nextDouble();
  57. System.out.println("Enter the second number to be calucalted (If dividing, this is the denominator):");
  58. double n2 = input.nextDouble();
  59.  
  60. // =======================
  61. // Addition
  62. // =======================
  63. if (function.equals("+")) {
  64. double sum = n1 + n2;
  65. System.out.println(n1 + "+" + n2 + " = " + sum);
  66. System.out.println("e = end | c = clear | m = save | r = recall");
  67. String command = input.next();
  68. // input.nextLine();
  69. switch (command) {
  70. case "e":
  71. end();
  72. break;
  73. case "c":
  74. clear();
  75. break;
  76. case "m":
  77. save(sum);
  78. break;
  79. case "r":
  80. recall();
  81. break;
  82. default:
  83. System.out.println("Default");
  84. save(sum);
  85. break;
  86. }
  87.  
  88. }
  89. // =======================
  90. // Subtraction
  91. // =======================
  92. else if (function.equals("-")) {
  93. double sum = n1 - n2;
  94. System.out.println(n1 + "-" + n2 + " = " + sum);
  95. System.out.println("e = end | c = clear | m = save | r = recall");
  96. String command = input.next();
  97. // input.nextLine();
  98. switch (command) {
  99. case "e":
  100. end();
  101. break;
  102. case "c":
  103. clear();
  104. break;
  105. case "m":
  106. save(sum);
  107. break;
  108. case "r":
  109. recall();
  110. break;
  111. }
  112. }
  113. // =======================
  114. // Multiplication
  115. // =======================
  116. else if (function.equals("*")) {
  117. double sum = n1 * n2;
  118. System.out.println(n1 + "*" + n2 + " = " + sum);
  119. System.out.println("e = end | c = clear | m = save | r = recall");
  120. String command = input.next();
  121. // input.nextLine();
  122. switch (command) {
  123. case "e":
  124. end();
  125. break;
  126. case "c":
  127. clear();
  128. break;
  129. case "m":
  130. save(sum);
  131. break;
  132. case "r":
  133. recall();
  134. break;
  135. }
  136. }
  137. // =======================
  138. // Division
  139. // =======================
  140. else if (function.equals("/")) {
  141. double sum = n1 / n2;
  142. System.out.println(n1 + "/" + n2 + " = " + sum);
  143. System.out.println("e = end | c = clear | m = save | r = recall");
  144. String command = input.next();
  145. // input.nextLine();
  146. switch (command) {
  147. case "e":
  148. end();
  149. break;
  150. case "c":
  151. clear();
  152. break;
  153. case "m":
  154. save(sum);
  155. break;
  156. case "r":
  157. recall();
  158. break;
  159. }
  160. }
  161. // =======================
  162. // Mod
  163. // =======================
  164. else if (function.equals("%")) {
  165. double sum = n1 % n2;
  166. System.out.println(n1 + "%" + n2 + " = " + sum);
  167. System.out.println("e = end | c = clear | m = save | r = recall");
  168. String command = input.next();
  169. // input.nextLine();
  170. switch (command) {
  171. case "e":
  172. end();
  173. break;
  174. case "c":
  175. clear();
  176. break;
  177. case "m":
  178. save(sum);
  179. break;
  180. case "r":
  181. recall();
  182. break;
  183. }
  184. }
  185. }
  186.  
  187. // =======================
  188. // Dictate loop duration:
  189. // =======================
  190. System.out.println("Would you like to continue? (Y|N): ");
  191. String ans = input.nextLine();
  192. if (ans.equals("N") || ans.equals("n")) {
  193. System.out.println("Closing Program");
  194. loop = false;
  195. end();
  196. }
  197. }
  198. }
Runtime error #stdin #stdout #stderr 0.05s 4386816KB
stdin
Standard input is empty
stdout
e = end | c = clear | m = save | r = recall | o = continue
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1371)
	at Ideone.commands(Main.java:38)
	at Ideone.main(Main.java:52)