-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.java
75 lines (70 loc) · 1.74 KB
/
Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
public class Test {
static Scanner scan;
public static void main(String[] args) {
scan = new Scanner(System.in);
loop: while (true) {
String input = scan.nextLine();
switch (input) {
case "start":
TakeTest();
break;
case "create":
String question = scan.nextLine();
CreateTest(question);
break;
case "stop":
break loop;
}
}
scan.close();
}
static void TakeTest() {
Scanner FindQuestion = new Scanner("questions.txt");
ArrayList<Question> Questions = new ArrayList<Questions>;
while(FindQuestion.hasNextLine){
String questionMsg = FindQuestion.nextLine();
String[] options = FindQuestion.nextLine().split(",~,");
Question question = new Question(questionMsg, options);
Questions.Add(question);
}
System.out.println("");
}
public class Question
{
private String QuestionMsg;
private String[] Answers ;
public Questions(String q, String[] answers)
{
Answers = answers;
QuestionMsg = q;
}
static void AskQuestion() {
answer = Answers[0];
shuffledAnswers = shuffleArray(Answers);
System.out.println(QuestionMsg);
System.out.println(shuffledAnswers.join("/n"));
Scaner answerInput = new Scanner(System.in);
String userAnswer = shuffledAnswers[answerInput.nextLine()-1];
if (userAnswer.Equals(answer){
System.out.println("Correct!");
}
else {
System.out.println("Nope!");
}
}
static String[] shuffleArray(String[] ar)
{
Random rnd = ThreadLocalRandom.current();
for (int i = ar.length - 1; i > 0; i--)
{
int index = rnd.nextInt(i + 1);
// Simple swap
int a = ar[index];
ar[index] = ar[i];
ar[i] = a;
return ar;
}
}
}