Guest User

Untitled

a guest
Apr 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.02 KB | None | 0 0
  1. // Allows Keyboard Input.
  2. import java.util.Scanner;
  3. // Generates Random Number
  4. import java.util.Random;
  5.  
  6. // Class name is "program"
  7. public class program {
  8. public static void main(String[] args) {
  9. // Initial Question, Displays Problem Choices
  10. System.out.println("How Many Questions Would You Like?");
  11. // Accept Input For How Many Questions That The User Wants
  12. Scanner sc = new Scanner(System.in);
  13. Double num;
  14. num = sc.nextDouble();
  15. // Sets Up How Many Times The Program Needs To Run To Repeat For How Many
  16. // Questions.
  17. Double questions;
  18. // Start To Count How Many Problems That The User Got Right.
  19. Double right;
  20. // Sets Needed Doubles To 0
  21. right = 0.0;
  22. questions = 0.0;
  23. // Update Questions Asked
  24. Double questionsasked;
  25. questionsasked = questions;
  26. // Will Repeat However Many Times That The User wants for questions.
  27. while (questions < num) { // Compares Initial value of questions to num,is how many questions that the
  28. // user wants.
  29. // Ask User What Type Of Problem
  30. System.out.println("What Kind Of Problem Would You Like?");
  31. // 1 for Addition, 2 for Subtraction, 3 For Multiplication, 4 for Division
  32. System.out.println("1 for "+", 2 for "-", 3 for "*", 4 for "/"");
  33. // Takes Input Values For Problem Type
  34. Scanner sd = new Scanner(System.in);
  35. Double input;
  36. input = sc.nextDouble();
  37. // Register What Problem They Would Like
  38. // Input is what type of problem user wants
  39. if (input == 1) {
  40. // Addition Problem, Passes Number Of Questions Right, and other necessary
  41. // things
  42. // Adds Value To Number Of Questions Asked, Used To Find Percentage Correct
  43. questions = questions + 1.0;
  44. // Calls Method
  45. add(right, questions, questionsasked);
  46. } else if (input == 2) {
  47. // Subtraction Problem, Passes Number Of Questions Right, and other necessary
  48. // things
  49. // Adds Value To Number Of Questions Asked, Used To Find Percentage Correct
  50. questions = questions + 1.0;
  51. // Calls Method
  52. subtract(right, questions, questionsasked);
  53.  
  54. } else if (input == 3) {
  55. // Multiply Problem, Passes Number Of Questions Right, and other necessary
  56. // things
  57. // Adds Value To Number Of Questions Asked, Used To Find Percentage Correct
  58. questions = questions + 1.0;
  59. // Calls Method
  60. multiply(right, questions, questionsasked);
  61.  
  62. } else if (input == 4) {
  63. // Division Problem, Passes Number Of Questions Right, and other necessary
  64. // things
  65. // Adds Value To Number Of Questions Asked, Used To Find Percentage Correct
  66. questions = questions + 1.0;
  67. // Calls Method
  68. divide(right, questions, questionsasked);
  69.  
  70. } else {
  71. // If Answer to what type of problem they want is not 1-4 it will print this.
  72. System.out.println("Not A Valid Problem.");
  73. }
  74. }
  75. Double calcper;
  76. calcper = right / questions;
  77. Double calcperfinal;
  78. calcperfinal = calcper * 100;
  79. System.out.println("You Got " + calcperfinal + "% Correct");
  80. // Lets User Know That The Program Is Done Running!
  81. System.out.println("Program Is Done Running!"); // This Is The Very Last Thing That Happens.
  82. }
  83.  
  84. // Addition Method
  85. public static Double add(Double right, Double questions, Double questionsasked) {
  86. // Computer FeedBack
  87. System.out.println("OK, Let's Add!");
  88. // THIS IS THE RANDOM NUMBER GENERATOR
  89. Random rand = new Random(); // This Declares The Random Number
  90. Double rnumber = rand.nextInt((int) 100.0) + 0.0; // 100 Is The Max, 0 Is The Min.
  91. // THIS IS THE RANDOM NUMBER GENERATOR 2
  92. Random rand2 = new Random(); // This Declares The Random Number
  93. Double rnumber2 = rand2.nextInt((int) 100.0) + 0.0; // 100 Is The Max, 0 Is The Min.
  94. // This Will Ask The Question!
  95. System.out.println("What Is, " + rnumber + " + " + rnumber2 + "?"); // This Will Ask Question.
  96. // Takes Input Values For What User Thinks Answer Is.
  97. Scanner sc = new Scanner(System.in);
  98. Double add; // This Is The User Answer
  99. add = sc.nextDouble(); // This Sets Current Scanner To The User Answer
  100. // Tell User If It Is Right Or Wrong!
  101. int answer = (int) (rnumber + rnumber2); // Creates INT To Determine The Right Answer
  102. // Used If user Got Question Correct
  103. if (add == answer) { // Compares User Answer To The Correct Computer Answer
  104. System.out.println("Correct!"); // Prints Out Correct
  105. right = right + 1.0;
  106. return right;
  107. // Used If user Got Question Incorrect
  108. } else {
  109. System.out.println("No, the correct answer is " + answer); // Prints The Correct Answer.
  110. return right;
  111. }
  112. }
  113.  
  114. // Subtraction Method
  115. public static Double subtract(Double right, Double questions, Double questionsasked) {
  116. // Computer Feedback
  117. System.out.println("OK, Let's Subtract!");
  118. // THIS IS THE RANDOM NUMBER GENERATOR
  119. Random rand = new Random(); // This Declares The Random Number
  120. Double rnumber = (double) (rand.nextInt(100) + 0.0); // 100 Is The Max, 0 Is The Min.
  121. // THIS IS THE RANDOM NUMBER GENERATOR 2
  122. Random rand2 = new Random(); // This Declares The Random Number
  123. Double rnumber2 = (double) (rand2.nextInt(100) + 0.0); // 100 Is The Max, 0 Is The Min.
  124. // This Will Ask The Question!
  125. System.out.println("What Is, " + rnumber + " - " + rnumber2 + "?"); // This Will Ask Question.
  126. // Takes Input Values For What User Thinks Answer Is.
  127. Scanner sc = new Scanner(System.in);
  128. Double sub; // This Is The User Answer
  129. sub = sc.nextDouble(); // This Sets Current Scanner To The User Answer
  130. // Tell User If It Is Right Or Wrong!
  131. int answer = (int) (rnumber - rnumber2); // Creates INT To Determine The Right Answer
  132. // Used If User gets Question Correct
  133. if (sub == answer) { // Compares User Answer To The Correct Computer Answer
  134. System.out.println("Correct!"); // Prints Out Correct
  135. right = right + 1;
  136. return right;
  137. // Used If User Gets Question Incorrect
  138. } else {
  139. System.out.println("No, the correct answer is " + answer); // Prints The Correct Answer.
  140. if (questionsasked == 1.0 || questions == 1.0 && right == 0.0) {
  141. System.out.println("You Got %0 Right.");
  142. } else {
  143. return right;
  144. }
  145. }
  146. return questions; // Updates Value Of Questions Asked
  147. }
  148.  
  149. // Multiplication Method
  150. public static Double multiply(Double right, Double questions, Double questionsasked) {
  151. // Computer FeedBack
  152. System.out.println("OK, Let's Multiply!");
  153. // THIS IS THE RANDOM NUMBER GENERATOR
  154. Random rand = new Random(); // This Declares The Random Number
  155. Double rnumber = (double) (rand.nextInt(100) + 0); // 100 Is The Max, 0 Is The Min.
  156. // THIS IS THE RANDOM NUMBER GENERATOR 2
  157. Random rand2 = new Random(); // This Declares The Random Number
  158. Double rnumber2 = (double) (rand2.nextInt(100) + 0); // 100 Is The Max, 0 Is The Min.
  159. // This Will Ask The Question!
  160. System.out.println("What Is, " + rnumber + " * " + rnumber2 + "?"); // This Will Ask Question.
  161. // Takes Input Values For What User Thinks Answer Is.
  162. Scanner sc = new Scanner(System.in);
  163. Double mul; // This Is The User Answer
  164. mul = sc.nextDouble(); // This Sets Current Scanner To The User Answer
  165. // Tell User If It Is Right Or Wrong!
  166. int answer = (int) (rnumber * rnumber2); // Creates INT To Determine The Right Answer
  167. // Used If User Gets Question Correct
  168. if (mul == answer) { // Compares User Answer To The Correct Computer Answer
  169. System.out.println("Correct!"); // Prints Out Correct
  170. right = right + 1.0;
  171. // Used If User Gets Question Incorrect
  172. } else {
  173. System.out.println("No, the correct answer is " + answer); // Prints The Correct Answer.
  174. return right;
  175. }
  176. return questions; // Updates Value Of Questions Asked
  177. }
  178.  
  179. // Division Method
  180. public static Double divide(Double right, Double questions, Double questionsasked) {
  181. // Computer FeedBack
  182. System.out.println("OK, Let's Divide!");
  183. // THIS IS THE RANDOM NUMBER GENERATOR
  184. Random rand = new Random(); // This Declares The Random Number
  185. Double rnumber = (double) (rand.nextInt(100) + 0.0); // 100 Is The Max, 0 Is The Min.
  186. // THIS IS THE RANDOM NUMBER GENERATOR 2
  187. Random rand2 = new Random(); // This Declares The Random Number
  188. Double rnumber2 = (double) rand2.nextInt(100) + 0.0; // 100 Is The Max, 0 Is The Min.
  189. // This Will Ask The Question!
  190. System.out.println("What Is, " + rnumber + " / " + rnumber2 + "?" + ", Round To The Nearest 100th Place."); // This
  191. // Will
  192. // Ask
  193. // Question.
  194. // Takes Input Values For What User Thinks Answer Is.
  195. Scanner sc = new Scanner(System.in);
  196. Double div; // This Is The User Answer
  197. div = sc.nextDouble(); // This Sets Current Scanner To The User Answer
  198. // Tell User If It Is Right Or Wrong!
  199. double answer = (rnumber / rnumber2); // Creates Double To Determine The Right Answer
  200. double answerrounded = Math.round(answer * 100.0) / 100.0; // Creates Answer To The Nearest 100th
  201. // Used If User Gets Question Correct
  202. if (div == answerrounded) { // Compares User Answer To The Correct Computer Answer
  203. System.out.println("Correct!"); // Prints Out Correct
  204. right = right + 1.0;
  205. return right;
  206. // used If User Gets Question Incorrect
  207. } else {
  208. System.out.println("No, the correct answer is " + answerrounded); // Prints The Correct Answer.
  209. }
  210. return questions; // Updates Value Of Questions Asked
  211. }
  212. }
Add Comment
Please, Sign In to add comment