Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. import java.util.Random;
  4.  
  5. public class AlgebraTutor {
  6.  
  7. static Random random = new Random();
  8.  
  9. static int m = -100 + random.nextInt(201);
  10. static int x = -100 + random.nextInt(201);
  11. static int b = -100 + random.nextInt(201);
  12. static int y = -100 + random.nextInt(201);
  13.  
  14. static int correct_answer_y = (m * x) + b;
  15. static int correct_answer_m = (y - b) / x;
  16. static int correct_answer_b = (y - (m * x));
  17.  
  18. static Scanner input = new Scanner(System.in);
  19.  
  20. static Scanner selection = new Scanner(System.in);
  21.  
  22. static int user_selection = 0;
  23.  
  24. public static void main(String[] args) {
  25. while (user_selection != 4) {
  26. prompt();
  27. }
  28. }
  29.  
  30. public static void prompt() {
  31.  
  32. System.out.println("If you would like to solve for y, please enter 1.");
  33. System.out.println("If you would like to solve for m, please enter 2.");
  34. System.out.println("If you would like to solve for b, please enter 3.");
  35. System.out.println("If you would like to quit, please enter 4.");
  36. int user_selection = input.nextInt();
  37.  
  38. while ((user_selection != 1) && (user_selection != 2) && (user_selection != 3) && (user_selection != 4)) {
  39. user_selection = input.nextInt();
  40. }
  41.  
  42. if (user_selection == 1) {
  43. solveForY();
  44. }
  45.  
  46. if (user_selection == 2) {
  47. solveForM();
  48. }
  49.  
  50. if (user_selection == 3) {
  51. solveForB();
  52. }
  53.  
  54. if (user_selection == 4) {
  55. System.exit(0);
  56.  
  57. }
  58.  
  59.  
  60. }
  61.  
  62. public static boolean solveForY() {
  63.  
  64. System.out.println("Given: \n");
  65. System.out.println("m = " + m);
  66. System.out.println("x = " + x);
  67. System.out.println("b = " + b);
  68. System.out.println();
  69. System.out.print("What is the value of y? ");
  70.  
  71. int user_answer = input.nextInt();
  72.  
  73. if (user_answer != correct_answer_y) {
  74. System.out.println("Sorry, that's wrong. The answer is " + correct_answer_y);
  75. }
  76.  
  77. else {
  78. System.out.println("Correct!");
  79. }
  80. return (user_answer != correct_answer_y);
  81. }
  82. public static boolean solveForM() {
  83.  
  84. System.out.println("Given: \n");
  85. System.out.println("y = " + y);
  86. System.out.println("x = " + x);
  87. System.out.println("b = " + b);
  88. System.out.println();
  89. System.out.print("What is the value of m? ");
  90.  
  91. int user_answer = input.nextInt();
  92.  
  93. if (user_answer != correct_answer_m) {
  94. System.out.println("Sorry, that's wrong. The answer is " + correct_answer_m + ".");
  95. }
  96.  
  97. else {
  98. System.out.println("Correct!");
  99. }
  100. return (user_answer != correct_answer_m);
  101.  
  102. }
  103.  
  104. public static boolean solveForB() {
  105.  
  106. System.out.println("Given: \n");
  107. System.out.println("y = " + y);
  108. System.out.println("x = " + x);
  109. System.out.println("m = " + m);
  110. System.out.println();
  111. System.out.print("What is the value of b? ");
  112.  
  113. int user_answer = input.nextInt();
  114.  
  115. if (user_answer != correct_answer_b) {
  116. System.out.println("Sorry, that's wrong. The answer is " + correct_answer_b + ".");
  117. }
  118.  
  119. else {
  120. System.out.println("Correct!");
  121. }
  122. return (user_answer != correct_answer_b);
  123.  
  124. }
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement