-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuiz.java
More file actions
71 lines (59 loc) · 1.81 KB
/
Copy pathQuiz.java
File metadata and controls
71 lines (59 loc) · 1.81 KB
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
// AP CS 18-19
// Testing and Debugging Activity
import java.util.*;
public class Quiz{
public Scanner in;
public static boolean isYes(String text){
return text.toLowerCase() == "yes";
}
public static ArrayList makeQuestions(){
int num = 0;
while(isYes(in.next())){
System.out.println("Do you want a free response or multiple choice question? Enter F or M. ");
String type = in.next();
String text;
if (type.equals("F")){
System.out.println("Enter the text of your question. ");
text = in.next();
System.out.println("Enter the answer to your questions. ");
String answer = in.next();
qs += new Question(text, answer, num);
num++;
}
else{
System.out.println("Enter the text of your question. ");
System.out.println("How many answer choices do you have? ");
MultipleChoice m = new MultipleChoice(text, "", num);
int numChoices = in.nextInt();
for (int i = 0; i < numChoices; i++){
System.out.println("Enter choice: ");
String choice = in.next();
System.out.println("Is this choice correct? yes or no ");
boolean isCorrect = isYes(in.next());
m.addChoice(choice, isCorrect);
}
qs.add(m);
}
System.out.println("Do you have any more questions? yes or no");
}
return qs;
}
public static void askQuestions(ArrayList<Question> questions){
for (MultipleChoice q: questions){
q.display();
System.out.println("Enter the answer to the question. If it is multiple choice enter the letter.");
if (q.checkAnswer(in.next())){
System.out.println("Correct!");
}
else{
System.out.println("Incorrect.");
}
}
System.out.println("You have finished the quiz.");
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
makeQuestions();
askQuestions();
}
}