Skip to content

Commit 4d3e396

Browse files
feat: adds Devyn's quiz java port (#123)
1 parent a9a4311 commit 4d3e396

File tree

12 files changed

+686
-0
lines changed

12 files changed

+686
-0
lines changed

lesson_02/quiz_java/.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+

lesson_02/quiz_java/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
This file was generated by the Gradle 'init' task.
3+
*/
4+
5+
6+
plugins {
7+
java
8+
id("org.springframework.boot") version "3.1.0"
9+
id("io.spring.dependency-management") version "1.1.0"
10+
application
11+
}
12+
13+
14+
java {
15+
toolchain {
16+
languageVersion.set(JavaLanguageVersion.of(21))
17+
}
18+
}
19+
20+
repositories {
21+
mavenCentral()
22+
}
23+
24+
dependencies {
25+
implementation("org.apache.commons:commons-text:1.10.0")
26+
implementation(project(":codedifferently-instructional:instructional-lib")) // <-- the link to the specific module
27+
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
28+
implementation("org.springframework.boot:spring-boot-starter")
29+
testImplementation("org.springframework.boot:spring-boot-starter-test")
30+
31+
}
32+
33+
34+
35+
application {
36+
// Define the main class for the application.
37+
application { mainClass.set("quiz_java.App") }
38+
tasks.test { useJUnitPlatform() }
39+
40+
}
41+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
/*
3+
* This source file was generated by the Gradle 'init' task
4+
*/
5+
package quiz_java;
6+
7+
/**
8+
* Java port of the assignment app using codedifferently-instructional library
9+
*/
10+
public class App {
11+
public static void main(String[] args) {
12+
System.out.println("Starting Quiz Java Application...");
13+
14+
try {
15+
// Initialize and run the lesson
16+
Lesson2 lesson = new Lesson2();
17+
lesson.run();
18+
19+
} catch (Exception e) {
20+
System.err.println("Error running quiz: " + e.getMessage());
21+
e.printStackTrace();
22+
}
23+
}
24+
}
25+
26+
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
package quiz_java;
2+
3+
4+
import java.util.Arrays;
5+
import java.util.LinkedHashMap;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
import com.codedifferently.instructional.quiz.AnswerChoice;
10+
import com.codedifferently.instructional.quiz.MultipleChoiceQuizQuestion;
11+
import com.codedifferently.instructional.quiz.QuizPrinter;
12+
import com.codedifferently.instructional.quiz.QuizQuestion;
13+
14+
/**
15+
* Java port of Lesson2 using codedifferently-instructional library.
16+
*/
17+
public class Lesson2 {
18+
19+
20+
21+
private QuizQuestion[] quizQuestions;
22+
private static final int EXPECTED_NUMBER_OF_QUESTIONS = 10;
23+
24+
25+
public void run() {
26+
List<QuizQuestion> quizQuestions = makeQuizQuestions();
27+
if (quizQuestions == null) {
28+
throw new IllegalStateException("Quiz questions cannot be null");
29+
}
30+
QuizPrinter printer = new QuizPrinter();
31+
printer.printQuiz(quizQuestions);
32+
}
33+
34+
public static List<QuizQuestion> makeQuizQuestions() {
35+
return Arrays.asList(
36+
makeQuestion0(),
37+
makeQuestion1(),
38+
makeQuestion2(),
39+
makeQuestion3(),
40+
makeQuestion4(),
41+
makeQuestion5(),
42+
makeQuestion6(),
43+
makeQuestion7(),
44+
makeQuestion8(),
45+
makeQuestion9(),
46+
makeQuestion10()
47+
);
48+
}
49+
50+
private static QuizQuestion makeQuestion0() {
51+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
52+
choices.put(AnswerChoice.A, "To make backups of files");
53+
choices.put(AnswerChoice.B, "To keep a record of changes over time");
54+
choices.put(AnswerChoice.C, "To delete unnecessary files");
55+
choices.put(AnswerChoice.D, "To run code more efficiently");
56+
return new MultipleChoiceQuizQuestion(
57+
0,
58+
"What is the main purpose of version control?",
59+
choices,
60+
AnswerChoice.UNANSWERED // TODO: replace with the correct answer
61+
);
62+
}
63+
64+
private static QuizQuestion makeQuestion1() {
65+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
66+
choices.put(AnswerChoice.A, "A duplicate copy of a repository that you own and modify");
67+
choices.put(AnswerChoice.B, "A temporary backup of the code");
68+
choices.put(AnswerChoice.C, "A tool for merging branches");
69+
choices.put(AnswerChoice.D, "A way to delete a repository");
70+
return new MultipleChoiceQuizQuestion(
71+
1,
72+
"What is a fork in Git?",
73+
choices,
74+
AnswerChoice.UNANSWERED // TODO
75+
);
76+
}
77+
78+
private static QuizQuestion makeQuestion2() {
79+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
80+
choices.put(AnswerChoice.A, "Pull the latest changes");
81+
choices.put(AnswerChoice.B, "Commit changes locally");
82+
choices.put(AnswerChoice.C, "Push changes to the server");
83+
choices.put(AnswerChoice.D, "Write code directly in GitHub");
84+
return new MultipleChoiceQuizQuestion(
85+
2,
86+
"Which of the following is NOT part of the basic Git workflow?",
87+
choices,
88+
AnswerChoice.UNANSWERED // TODO
89+
);
90+
}
91+
92+
private static QuizQuestion makeQuestion3() {
93+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
94+
choices.put(AnswerChoice.A, "git commit");
95+
choices.put(AnswerChoice.B, "git merge");
96+
choices.put(AnswerChoice.C, "git branch");
97+
choices.put(AnswerChoice.D, "git pull");
98+
return new MultipleChoiceQuizQuestion(
99+
3,
100+
"What command is used to combine changes from different branches?",
101+
choices,
102+
AnswerChoice.UNANSWERED // TODO
103+
);
104+
}
105+
106+
private static QuizQuestion makeQuestion4() {
107+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
108+
choices.put(AnswerChoice.A, "Eclipse");
109+
choices.put(AnswerChoice.B, "IntelliJ IDEA");
110+
choices.put(AnswerChoice.C, "NetBeans");
111+
choices.put(AnswerChoice.D, "VS Code");
112+
return new MultipleChoiceQuizQuestion(
113+
4,
114+
"Which IDE is being used in the class?",
115+
choices,
116+
AnswerChoice.UNANSWERED // TODO
117+
);
118+
}
119+
120+
private static QuizQuestion makeQuestion5() {
121+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
122+
choices.put(AnswerChoice.A, "Extensions");
123+
choices.put(AnswerChoice.B, "Debugger");
124+
choices.put(AnswerChoice.C, "Dev Containers");
125+
choices.put(AnswerChoice.D, "Source Control");
126+
return new MultipleChoiceQuizQuestion(
127+
5,
128+
"What feature allows developers to work from the same pre-configured environment in VS Code?",
129+
choices,
130+
AnswerChoice.UNANSWERED // TODO
131+
);
132+
}
133+
134+
private static QuizQuestion makeQuestion6() {
135+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
136+
choices.put(AnswerChoice.A, "Editing and refactoring code");
137+
choices.put(AnswerChoice.B, "Browsing code");
138+
choices.put(AnswerChoice.C, "Playing music");
139+
choices.put(AnswerChoice.D, "Managing source control");
140+
return new MultipleChoiceQuizQuestion(
141+
6,
142+
"What is NOT a reason for using an IDE?",
143+
choices,
144+
AnswerChoice.UNANSWERED // TODO
145+
);
146+
}
147+
148+
private static QuizQuestion makeQuestion7() {
149+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
150+
choices.put(AnswerChoice.A, "pwd");
151+
choices.put(AnswerChoice.B, "ls");
152+
choices.put(AnswerChoice.C, "cd");
153+
choices.put(AnswerChoice.D, "mkdir");
154+
return new MultipleChoiceQuizQuestion(
155+
7,
156+
"What is the command to list files in the current directory?",
157+
choices,
158+
AnswerChoice.UNANSWERED // TODO
159+
);
160+
}
161+
162+
private static QuizQuestion makeQuestion8() {
163+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
164+
choices.put(AnswerChoice.A, "pwd");
165+
choices.put(AnswerChoice.B, "ls");
166+
choices.put(AnswerChoice.C, "cd");
167+
choices.put(AnswerChoice.D, "mkdir");
168+
return new MultipleChoiceQuizQuestion(
169+
8,
170+
"Which command is used to change directories in the terminal?",
171+
choices,
172+
AnswerChoice.UNANSWERED // TODO
173+
);
174+
}
175+
176+
private static QuizQuestion makeQuestion9() {
177+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
178+
choices.put(AnswerChoice.A, "Change file or directory permissions");
179+
choices.put(AnswerChoice.B, "List files in a directory");
180+
choices.put(AnswerChoice.C, "Remove a file or directory");
181+
choices.put(AnswerChoice.D, "Copy a file or directory");
182+
return new MultipleChoiceQuizQuestion(
183+
9,
184+
"What does the command `chmod` do?",
185+
choices,
186+
AnswerChoice.UNANSWERED // TODO
187+
);
188+
}
189+
190+
private static QuizQuestion makeQuestion10() {
191+
Map<AnswerChoice, String> choices = new LinkedHashMap<>();
192+
choices.put(AnswerChoice.A, "⌘ + Shift + T");
193+
choices.put(AnswerChoice.B, "⌘ + Spacebar, then type \"terminal\"");
194+
choices.put(AnswerChoice.C, "⌘ + Q");
195+
choices.put(AnswerChoice.D, "⌘ + S, then type \"terminal\"");
196+
return new MultipleChoiceQuizQuestion(
197+
10,
198+
"What is the shortcut for getting to the Mac terminal?",
199+
choices,
200+
AnswerChoice.UNANSWERED // TODO
201+
);
202+
}
203+
}
204+
205+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* This source file was generated by the Gradle 'init' task
3+
*/
4+
package quiz_java;
5+
6+
import org.junit.jupiter.api.Test;
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class AppTest {
10+
@Test void appCanInstantiate() {
11+
App classUnderTest = new App();
12+
assertNotNull(classUnderTest, "app should be instantiable");
13+
}
14+
15+
@Test void lesson2CanInstantiate() {
16+
Lesson2 lesson = new Lesson2();
17+
assertNotNull(lesson, "Lesson2 should be instantiable");
18+
}
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file was generated by the Gradle 'init' task.
2+
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
3+
4+
[versions]
5+
guava = "33.0.0-jre"
6+
junit-jupiter = "5.10.2"
7+
8+
[libraries]
9+
guava = { module = "com.google.guava:guava", version.ref = "guava" }
10+
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
42.4 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)