-
Notifications
You must be signed in to change notification settings - Fork 1
/
Quizzer_Gonz.java
executable file
·151 lines (127 loc) · 3.91 KB
/
Quizzer_Gonz.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//Brandon Gonzalez
//Java
//I am soso sorry to whoever has to read this for th mess that happened in the questioner
//function. C++ habits made me do things that werent allowed in java, so i had to fix it
//last second. please forgive me
import Java.util.Scanner;
public class Quizzer_Gonz{
public static void main(String[] args) {
Quizzer test = new Quizzer();
test.questioner();
test.summary();
}
}
class QuizzerFunctions {
private double score = 1;
public String name;
public String mcQues1, mcQues2, mcQues3, mcQues4, frQues1, frQues2;
public String answer1, answer2, answer3, answer4, answer5, answer6;
//Here is the constructors
public QuizzerFunctions() {
mcQues1 = "Who was the first president of the US?\na:George Washington\nb: Obama\nc: Romney\nd: Dorian Chan";
mcQues2 = "Wha t is the average air velocity of an unladen swallow?\na:10 m/s \nb:12 m/s\nc:14 m/s\nd:Dorian Speed";
mcQues3 = "What is the meaning of life?\na:42\nb:52\nc:24\nd:100";
mcQues4 = "What is Dorian's 5th period class?\na: Math\nb:Swag theory\nc: Compsci AP/nd:English 2";
frQues1 = "What is your favorite color?";
frQues2 = "What do you think of facebooks privacy policy?";
}
/******************************
** Should probably find a more*
** secure way to do this *
*******************************/
public void getName(String name){
this.name = name;
}
public void pushScore(double value) {
score += value;
}
public double getScore() {
return score;
}
public void popScore(double value){
if((score - value) <= 0) {
score = 0;
} else {
score -= value;
}
}
public void pushQuestion(String question) {
System.out.println(question);
}
public String getResponse() {
Scanner input = new Scanner(System.in);
answer = input.nextLine();
return answer;
}
public boolean checkAnswer(String input, String answer, int points){
int tries = 0;
if(input.equals(answer)) {
return true;
pushScore();
} else {
System.out.println("That is incorrect!");
while(!input.equals(answer) || tries < 3 ) {
input = getResponse();
}
return false;
}
}
public void cls() {
System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
}
public void questioner() {
QuizzerFunctions quiz = new QuizzerFunctions();
//Starting of the quiz
quiz.pushQuestion("What is your name?");
name = getResponse();
if(name.equals("")) {
System.out.println("You didnt enter your name, so you lose a point");
quiz.popScore();
}
//First actual question
pushQuestion(mcQues1);
quiz.answer1 = quiz.getResponse();
quiz.checkAnswer(quiz.answer1, "a", 1);
quiz.cls();
//Second question
quiz.pushQuestion(mcQues2);
quiz.answer2 = getResponse();
quiz.checkAnswer(quiz.answer2, "b");
quiz.cls();
if(quiz.answer2.equals("b")) {
//Peanut butter third question time
quiz.pushQuestion(mcQues3);
quiz.answer3 = quiz.getResponse();
quiz.checkAnswer(quiz.anwer3, "a");
}
quiz.cls();
//Question 4
quiz.pushQuestion(mcQues4);
quiz.answer4 = quiz.getResponse();
quiz.checkAnswer(quiz.answer4,"c");
//question 5
quiz.pushQuestion(quiz.frQues1);
quiz.answer5 = quiz.getResponse();
quiz.checkAnswer(quiz.answer5, "blue");
quiz.cls();
//question 6
quiz.pushQuestion(quiz.frQues2);
quiz.answer6 = quiz.getResponse();
int tries = 0;
while(tries < 4){
if(quiz.answer5.equals("no thoughts") || quiz.answer5.equals("bad") || quiz.answer5.equals("its bad")){
quiz.pushScore();
tries = 100; //this is pretty bad practice. dont judge me
} else {
System.out.println("That is incorrect!\nPlease try again!!!");
quiz.answer6 = quiz.getResponse();
tries++;
}
}
}
public void summary(){
System.out.println("You scored a total of " + getScore() + " Out of 6");
System.out.println("Percentage: " + (getScore/6 * 100) + "%");
System.out.printf("Your answers were %s\n%s\n%s\n%s\n%s\n%s\n", answer1, answer2, answer3, answer4, answer5, answer6);
}
}