Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3. import java.util.ArrayList;
  4.  
  5. public class AdditionQuizJava13 {
  6.  
  7.  
  8. void run() {
  9. Random random = new Random();
  10. ArrayList<String> questions = new ArrayList<String>();
  11.  
  12. System.out.println("1: New question");
  13. System.out.println("2: List all questions");
  14. System.out.println("0: Terminate the program");
  15.  
  16. }
  17. void newQuestion () {
  18. Scanner input = new Scanner(System.in);
  19. Random random = new Random();
  20. int command = input.nextInt();
  21. switch (command) {
  22. case 1:
  23. int randomNumber1 = random.nextInt(500);
  24. int randomNumber2 = random.nextInt(600);
  25.  
  26. String question = ("What is " + randomNumber1 + " + " + randomNumber2 + "?");
  27.  
  28.  
  29. System.out.println("What is " + randomNumber1 + " + " + randomNumber2 + "?");
  30. questions.add(question);
  31. int answer = input.nextInt();
  32.  
  33. break;
  34. case 2:
  35. System.out.println(questions);
  36. break;
  37. case 0:
  38. System.out.println("Bye!");
  39. return;
  40.  
  41. default:
  42. System.out.println("Wrong command, try again");
  43.  
  44. }
  45. }
  46.  
  47. void newQuestionOutput () {
  48. if (answer == randomNumber1 + randomNumber2) {
  49. System.out.println("The answer is correct");
  50. } else if (answer != randomNumber1 + randomNumber2) {
  51. System.out.println("The answer is incorrect");
  52. }
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59. public static void main(String[] args) {
  60. run();
  61. newQuestion();
  62. newQuestionOutput();
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement