Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import java.io.FileReader;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5. import java.util.Scanner;
  6.  
  7. /*George Job
  8. * Date: Mar 19, 2015
  9. * File: QuestionTester.java
  10. * Description:
  11. */
  12.  
  13. public class QuestionTester
  14. {
  15.  
  16. public static void main(String[] args)throws IOException
  17. {
  18. FileReader reader = new FileReader("/Users/jobge/Desktop/Java/FileStuff/src/TriviaBank");
  19.  
  20. //creates an ArrayList to store Questions
  21. ArrayList<Question> qBank = new ArrayList<Question>();
  22.  
  23. Scanner in2 = new Scanner(reader);
  24. Scanner in = new Scanner(System.in);
  25.  
  26. String quest, answer;
  27. //actually reads file until the end
  28. while(in2.hasNextLine())
  29. {
  30. quest = in2.nextLine();
  31. answer = in2.nextLine();
  32.  
  33. qBank.add(new Question(quest, answer, null));
  34. //stores information that was read into an ArrayList
  35. //of Questions
  36. }
  37.  
  38. int score = 0;
  39. for(int i=1; i<=5; i++)
  40. {
  41. Random gen = new Random();
  42. int qnum = gen.nextInt(20);
  43.  
  44. System.out.println("Question is: " + qBank.get(qnum).getQuestion());
  45. String inp = in.nextLine();
  46.  
  47. if(inp.equalsIgnoreCase(qBank.get(qnum).getAnswer()))
  48. {
  49. System.out.println("Correct!");
  50. score++;
  51. }
  52. else
  53. System.out.println("Incorrect! Answer is: " + qBank.get(qnum).getAnswer());
  54.  
  55. in2.close();
  56. reader.close();
  57. }
  58. System.out.println("Your score: " + score + "/5");
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement