Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.Scanner;
- import java.util.ArrayList;
- public class AdditionQuizJava13 {
- void run() {
- Random random = new Random();
- ArrayList<String> questions = new ArrayList<String>();
- System.out.println("1: New question");
- System.out.println("2: List all questions");
- System.out.println("0: Terminate the program");
- }
- void newQuestion () {
- Scanner input = new Scanner(System.in);
- Random random = new Random();
- int command = input.nextInt();
- switch (command) {
- case 1:
- int randomNumber1 = random.nextInt(500);
- int randomNumber2 = random.nextInt(600);
- String question = ("What is " + randomNumber1 + " + " + randomNumber2 + "?");
- System.out.println("What is " + randomNumber1 + " + " + randomNumber2 + "?");
- questions.add(question);
- int answer = input.nextInt();
- break;
- case 2:
- System.out.println(questions);
- break;
- case 0:
- System.out.println("Bye!");
- return;
- default:
- System.out.println("Wrong command, try again");
- }
- }
- void newQuestionOutput () {
- if (answer == randomNumber1 + randomNumber2) {
- System.out.println("The answer is correct");
- } else if (answer != randomNumber1 + randomNumber2) {
- System.out.println("The answer is incorrect");
- }
- }
- public static void main(String[] args) {
- run();
- newQuestion();
- newQuestionOutput();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement