Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updates Lesson 10 quiz #269

Merged
merged 8 commits into from Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions lesson_10/README.md
@@ -1,9 +1,23 @@
# Lesson 10

## Quiz Instructions

1. Sync your fork and create a new branch for your quiz.
2. Terminal into the `quiz` sub-directory and run the following command to take the quiz interactively:
```bash
./gradlew run --console=plain
```
3. If you would like to check your answers, you can run the following command:
```bash
./gradlew test -Dprofile=prod
```
4. Submit a PR with your response. Your last submission up to the cutoff deadline will be accepted (3/20/24 @ 1:20 PM ET).

## Homework

* TODO(anthonydmays): Add details
* Read HFDP 1-2.
* Complete [Applying SOLID principles](#applying-solid-principles) exercise.

## Custom Data Types
## Applying SOLID Principles

* TODO(anthonydmays): Add details
3 changes: 3 additions & 0 deletions lesson_10/quiz/quiz_app/build.gradle.kts
Expand Up @@ -44,6 +44,9 @@ tasks.named<Test>("test") {
if (System.getProperty("profile") != null) {
systemProperty("spring.profiles.active", System.getProperty("profile"))
}
if (System.getProperty("quizTaker") != null) {
systemProperty("quiz.quizTaker", System.getProperty("quizTaker"))
}
}


Expand Down
Expand Up @@ -9,10 +9,9 @@
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
Expand Down Expand Up @@ -70,12 +69,15 @@ private String promptForFileName(Scanner scanner) {
}

private void saveAnswersToFile(List<QuizQuestion> questions, String filename) {
Map<Integer, String> values =
questions.stream()
.collect(Collectors.toMap(QuizQuestion::getQuestionNumber, QuizQuestion::getAnswer));
var values = new LinkedHashMap<Integer, String>();
for (QuizQuestion question : questions) {
values.put(question.getQuestionNumber(), question.getAnswer());
}

var file = new File(getDataPath() + File.separator + filename + ".json");
file.getParentFile().mkdirs();
var gson = new GsonBuilder().setPrettyPrinting().create();

try (var writer = new FileWriter(file, false)) {
writer.write(gson.toJson(values));
} catch (IOException e) {
Expand Down