Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.31 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.util.ArrayList;
  5. import java.util.regex.*;  
  6.  
  7. public class QuestionsTest {
  8.         public static void main (String[] args) {
  9.  
  10.         Scanner in = new Scanner(System.in);
  11.        
  12.         Questions basicQuiz = new Questions();
  13.         Questions binaryQuiz = new Questions();
  14.  
  15.         /*
  16.                    
  17.         System.out.println("Please enter the file you want to read: ");
  18.         String filename = in.next();
  19.         //String filename = in.nextLine();
  20.         File fileIn = new File (filename);
  21.         try {  
  22.             Scanner file = new Scanner(fileIn);          
  23.             while(file.hasNextLine()) {
  24.                 // Get a line of the text file
  25.                 String line = file.nextLine();
  26.                
  27.                 // Separate the line into name and number
  28.                 String[] parts = line.split(",");
  29.                 String temp1Question = parts[0];
  30.                 String temp1Answer1 = parts[1];
  31.                 String temp1Answer2 = parts[2];
  32.                 String temp1Answer3 = parts[3];
  33.                 String temp1Answer4 = parts[4];
  34.                 String temp1corAnswer = parts[5];
  35.  
  36.                 // Create an entry and add it to the Student Details
  37.                 basicQuiz.add(temp1Question, temp1Answer1, temp1Answer2 , temp1Answer3, temp1Answer4, temp1corAnswer);
  38.                 }
  39.                 file.close();
  40.             }
  41.             catch( Exception e ) {
  42.             System.out.println( "Problem reading file: " + filename );
  43.             }
  44.            
  45.             System.out.println(basicQuiz);
  46.  
  47.         in.nextLine();
  48.  
  49.         int tempHolderswag = 0;
  50.         int loops = 0;
  51.         int arraySize = basicQuiz.size();
  52.  
  53.         for(int i = 0; i < arraySize; i++) {
  54.            
  55.             String correctValue1 = basicQuiz.get(i).getcorAnswer();
  56.             String questionlol = basicQuiz.get(i).getQuestion();
  57.             String output1 = basicQuiz.get(i).getAnswer1();
  58.             String output2 = basicQuiz.get(i).getAnswer2();
  59.             String output3 = basicQuiz.get(i).getAnswer3();
  60.             String output4 = basicQuiz.get(i).getAnswer4();
  61.  
  62.             System.out.println("Select a choice");
  63.             System.out.println(questionlol);
  64.             System.out.println("Options");
  65.             System.out.println(output1);
  66.             System.out.println(output2);
  67.             System.out.println(output3);
  68.             System.out.println(output4);
  69.  
  70.             String tempValue = in.nextLine();
  71.  
  72.  
  73.             if (tempValue.matches(correctValue1)) {
  74.                 System.out.println("You are correct");
  75.                 tempHolderswag += 1;
  76.  
  77.             } else {
  78.                 System.out.println("You are retarded");
  79.             }
  80.  
  81.         }
  82.  
  83.         //Score
  84.         System.out.println(tempHolderswag + " / 10");
  85.  
  86.        
  87.  
  88.                     //Add a Question to the array
  89.  
  90.         /*
  91.         System.out.println("Please enter the Question: ");
  92.         String tempQuestion = in.nextLine();
  93.         System.out.println("");
  94.  
  95.         System.out.println("Please enter Answer 1: ");
  96.         String tempAnswer1 = in.nextLine();
  97.         System.out.println("");
  98.  
  99.  
  100.         System.out.println("Please enter Answer 2: ");
  101.         String tempAnswer2 = in.nextLine();
  102.         System.out.println("");
  103.  
  104.         System.out.println("Please enter Answer 3: ");
  105.         String tempAnswer3 = in.nextLine();
  106.         System.out.println("");
  107.  
  108.         System.out.println("Please enter Answer4: ");
  109.         String tempAnswer4 = in.nextLine();
  110.  
  111.         System.out.println("Please enter the Correct Answer: ");
  112.         String tempcorAnswer = in.nextLine();
  113.  
  114.         basicQuiz.add(tempQuestion, tempAnswer1, tempAnswer2, tempAnswer3, tempAnswer4, tempcorAnswer);
  115.  
  116.         System.out.println(basicQuiz);
  117.  
  118.        
  119.  
  120.  
  121.  
  122.                 //Delete a Qusetion by index
  123.  
  124.         /*
  125.         System.out.println("Current Questions in General Knowledge:\n");
  126.         for(int i = 0 ; i < basicQuiz.size(); i++ ) {
  127.             String tempDelete = basicQuiz.get(i).getQuestion();
  128.             System.out.println((i+1) + ": " + tempDelete);
  129.         }
  130.         System.out.println("Please enter the index of user you want to delete\n");
  131.         int temptempSelection = in.nextInt();
  132.         int tempSelection = temptempSelection - 1;
  133.         basicQuiz.remove(tempSelection);
  134.         System.out.println("\nThe Question of Index: " + temptempSelection + " has now been deleted");
  135.  
  136.         for(int i = 0 ; i < basicQuiz.size(); i++ ) {
  137.             String tempDelete = basicQuiz.get(i).getQuestion();
  138.             System.out.println((i+1) + ": " + tempDelete);
  139.         }
  140.         */
  141.  
  142.  
  143. //End points
  144.  }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement