-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFragebogen.java
More file actions
161 lines (114 loc) · 4.81 KB
/
Fragebogen.java
File metadata and controls
161 lines (114 loc) · 4.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
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
152
153
154
155
156
157
158
159
160
161
import javax.swing.JOptionPane;
import java.util.Scanner;
import java.util.Map.Entry;
import java.util.LinkedHashMap;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Fragebogen {
private static LinkedHashMap<String, String> questionPairs = new LinkedHashMap<>();
public static void main(String[] args) {
// Prelaunch - Ask for name
Scanner sc = new Scanner(System.in);
System.out.print("Bitte gib deinen Namen ein, bevor das Quiz startet: ");
final String name = sc.nextLine();
// Load questions into Map
fillQuestionList();
String[] choices = {"eine Versionshistorie",
"eine direkte Codeanalyse",
"eine Urkunde (ausgestellt vom Ministerium für technische Entwicklung)"};
String input = retrieveUserInput(0, choices, choices[0]);
/* Decide whether your answer is right or wrong
- print "Falsch" on the Shell for each answer you consider as wrong
- repeat the steps above for every if-statement/given question!
- you can create a function if you are lazy/smart
*/
System.out.print("Die Antwort ist: ");
if (input == choices[0]) {
} else if (input == choices[1]) {
System.out.println("...");
} else if (input == choices[2]) {
}
String[] choices1 = {"Spendenbutton bei Amazon-Einkäufen",
"Partnerprogramme mit z.B Amazon, bei denen ein Anteil des Kaufpreises an das Projekt geht",
"Amazon-Werbung auf eigener Website schalten"};
String input1 = retrieveUserInput(1, choices1, choices1[0]);
System.out.print("Die Antwort ist");
if (input1 == choices1[0]) {
} else if (input1 == choices1[1]) {
} else if (input1 == choices1[2]) {
}
String[] choices2 = {"GNU GPL v2", "Apache Lizenz", "Mozilla Public License"};
String input2 = retrieveUserInput(2, choices2, choices2[0]);
System.out.print("Die Antwort ist");
if (input2 == choices2[0]) {
} else if (input2 == choices2[1]) {
} else if (input2 == choices2[2]) {
}
String[] choices3 = {"README", "Code of Conduct", "License", "Contributing File"};
String input3 = retrieveUserInput(3, choices3, choices3[0]);
System.out.print("Die Antwort ist");
if (input3 == choices3[0]) {
} else if (input3 == choices3[1]) {
} else if (input3 == choices3[2]) {
}
// Code-Eigenschaften-Fragebogen
String[] choices4 = {"Man stellt den Anwender möglicherweise vor eine Entscheidung",
"Software kann gelegentlich abstürzen, was zu Datenverlusten führt",
"Verschiedene Software kann mit verschiedenen Versionen kompatibel sein",
"Der Prozess benötigt mehr Arbeitsspeicher",
"Die Software springt dir ins Gesicht, wenn du es am wenigsten erwartest"};
String input4 = retrieveUserInput(4, choices4, choices4[0]);
System.out.print("Die Antwort ist: ");
if (input4 == choices4[0]) {
} else if (input4 == choices4[1]) {
} else if(input4 == choices4[2]) {
} else if(input4 == choices4[3]) {
} else if(input4 == choices4[4]) {
}
// Creates a text file containing your given answers
logIndividualScore(name);
}
// IMPLEMENT HERE
private static int correctAnswerCounter() {
/*
1. Implement a simple counter that counts the correct answers
- create a global variable
- iterate your global variable every time your answer is correct
- print "Richtig" on the Shell
*/
return 0;
}
private static void fillQuestionList() {
try (BufferedReader br = new BufferedReader(new FileReader("questions.txt"))) {
for(String line; (line = br.readLine()) != null; ) {
questionPairs.put(line, "");
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static String retrieveUserInput(int index, String[] choices, String answer) {
final String label = "DAS ULTIMATIVE OPEN SOURCE QUIZ";
final String currentQuestion = (String)questionPairs.keySet().toArray()[index];
final String clickedInput = ((String) JOptionPane.showInputDialog
(null, currentQuestion, label, JOptionPane.QUESTION_MESSAGE, null, choices, answer));
questionPairs.put(currentQuestion, clickedInput);
return clickedInput;
}
private static void logIndividualScore(String name) {
FileWriter log = null;
try {
log = new FileWriter(name + ".txt");
for(Entry<String, String> entry : questionPairs.entrySet())
log.write(entry.getKey() + "\n\t Deine Antwort: " + entry.getValue() + "\n\n");
log.write(correctAnswerCounter() + " von " + questionPairs.size() + " Fragen richtig beantwortet.\n");
log.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}