Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- /*George Job
- * Date: Mar 19, 2015
- * File: QuestionTester.java
- * Description:
- */
- public class QuestionTester
- {
- public static void main(String[] args)throws IOException
- {
- FileReader reader = new FileReader("/Users/jobge/Desktop/Java/FileStuff/src/TriviaBank");
- //creates an ArrayList to store Questions
- ArrayList<Question> qBank = new ArrayList<Question>();
- Scanner in2 = new Scanner(reader);
- Scanner in = new Scanner(System.in);
- String quest, answer;
- //actually reads file until the end
- while(in2.hasNextLine())
- {
- quest = in2.nextLine();
- answer = in2.nextLine();
- qBank.add(new Question(quest, answer, null));
- //stores information that was read into an ArrayList
- //of Questions
- }
- int score = 0;
- for(int i=1; i<=5; i++)
- {
- Random gen = new Random();
- int qnum = gen.nextInt(20);
- System.out.println("Question is: " + qBank.get(qnum).getQuestion());
- String inp = in.nextLine();
- if(inp.equalsIgnoreCase(qBank.get(qnum).getAnswer()))
- {
- System.out.println("Correct!");
- score++;
- }
- else
- System.out.println("Incorrect! Answer is: " + qBank.get(qnum).getAnswer());
- in2.close();
- reader.close();
- }
- System.out.println("Your score: " + score + "/5");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement