|
| 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 | + |
0 commit comments