Advertisement
Guest User

dap

a guest
Sep 16th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package hoa2mathapp_echaure;
  7.  
  8. import java.util.Scanner;
  9. import java.util.Random;
  10. public class HOA2MathApp_Echaure {
  11.  
  12. /**
  13. * @param args the command line arguments
  14. */
  15. public static void main(String[] args) {
  16. Scanner myObj = new Scanner(System.in);
  17. char operator = myObj.next().charAt(0);
  18.  
  19. int i = 0, a, user;
  20. Random rand = new Random();
  21.  
  22. while (i < 1) {
  23. System.out.println("~~~~~Welcome to Math Challenge!~~~~~\n");
  24. System.out.println(" To Start Please Choose The Operator That You Like");
  25. System.out.println(" | + | | - | | * | | / |");
  26.  
  27. switch (operator){
  28. case '+':
  29. System.out.println("Yoou have chosen Addition!");
  30. while (i < 5){
  31. int r1 = rand.nextInt(50);
  32. int r2 = rand.nextInt(50);
  33. System.out.println(r1 + " + " + r2);
  34. a = r1 + r2;
  35. user = myObj.nextInt();
  36. if (user == a){
  37. System.out.println("Correct!");
  38. i++;
  39. }
  40. else {
  41. System.out.println("Wrong Answer!");
  42. System.out.println(" The Answer is " + a);
  43. }
  44. }
  45. break;
  46. case '-':
  47. System.out.println("You have chosen Subtraction!");
  48. while (i < 5){
  49. int r1 = rand.nextInt(50);
  50. int r2 = rand.nextInt(50);
  51. System.out.println(r1 + " - " + r2);
  52. a = r1 - r2;
  53. user = myObj.nextInt();
  54. if (user == a){
  55. System.out.println("Correct!");
  56. i++;
  57. }
  58. else {
  59. System.out.println("Wrong Answer!");
  60. System.out.println(" The Answer is " + a);
  61. }
  62. }
  63. break;
  64. case '*':
  65. System.out.println("You have chosen Multiplication!");
  66. while (i < 5){
  67. int r1 = rand.nextInt(50);
  68. int r2 = rand.nextInt(50);
  69. System.out.println(r1 + " * " + r2);
  70. a = r1 * r2;
  71. user = myObj.nextInt();
  72. if (user == a){
  73. System.out.println("Correct!");
  74. i++;
  75. }
  76. else {
  77. System.out.println("Wrong Answer!");
  78. System.out.println(" The Answer is " + a);
  79. }
  80. }
  81. break;
  82. case '/':
  83. System.out.println("You have chosen Division!");
  84. while (i < 5){
  85. int r1 = rand.nextInt(50);
  86. int r2 = rand.nextInt(50);
  87. System.out.println(r1 + " / " + r2);
  88. a = r1 / r2;
  89. user = myObj.nextInt();
  90. if (user == a){
  91. System.out.println("Correct!");
  92. i++;
  93. }
  94. else {
  95. System.out.println("Wrong Answer!");
  96. System.out.println(" The Answer is " + a);
  97. }
  98. }
  99. break;
  100. default :
  101. System.out.println("\nPlease input a valid operator!");
  102. }
  103. System.out.println("Would you like to try again with a different operator?");
  104. System.out.println("Press 1 for YES and 2 for NO");
  105. char reply;
  106. c = myObj.nextInt();
  107. if (c == 2){
  108. i++;
  109. }
  110. else {
  111. return;
  112. }
  113. }
  114.  
  115. }
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement