SHARE
TWEET

Untitled

a guest Oct 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.nio.file.Files;
  2. import java.nio.file.Paths;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class Main {
  10.  
  11.     private static List<String> questions = new ArrayList<>();
  12.     private static List<String> options = new ArrayList<>();
  13.     private static List<String> answers = new ArrayList<>();
  14.     static int count = 0;
  15.  
  16.     public static void main(String[] args) throws Exception {
  17.         Scanner sc = new Scanner(System.in);
  18.         String lines = readFileAsString();
  19.  
  20.         Pattern pattern = Pattern.compile("[ \\t]*\\d+\\)[^\\n]+");
  21.         Matcher m = pattern.matcher(lines);
  22.         while (m.find()) {
  23.             questions.add(m.group());
  24.         }
  25.  
  26.         m.usePattern(Pattern.compile("(?:[ \\t]*[a-zA-Z]\\)[^\\n]+\\n)+"));
  27.         m.reset();
  28.         while (m.find()) {
  29.             options.add(m.group());
  30.         }
  31.  
  32.         m.usePattern(Pattern.compile("Answer:[^\\n]*"));
  33.         m.reset();
  34.         while (m.find()) {
  35.             answers.add(m.group());
  36.         }
  37.  
  38.         for (int i = 0; i < questions.size(); i++) {
  39.             System.out.println(questions.get(i));
  40.             System.out.println(options.get(i));
  41.  
  42.             char c = sc.next().charAt(0);
  43.             char answer = Character.toLowerCase(answers.get(i).charAt(8));
  44.  
  45.             if (c == answer) {
  46.                 count++;
  47.                 System.out.println("CORRECT");
  48.             } else {
  49.                 System.out.println("INCORRECT " + answer);
  50.             }
  51.             System.out.println();
  52.  
  53.         }
  54.         System.out.println("Ratio " + count + "/" + questions.size());
  55.     }
  56.  
  57.     private static String readFileAsString() throws Exception {
  58.         String data = "";
  59.         data = new String(Files.readAllBytes(Paths.get("questions.txt")));
  60.         return data;
  61.     }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top