Skip to content

Commit

Permalink
Merge branch 'code-differently:main' into lesson09
Browse files Browse the repository at this point in the history
  • Loading branch information
javyW authored Mar 20, 2024
2 parents b78a795 + 22bbc6f commit fd6d3e6
Showing 19 changed files with 534 additions and 168 deletions.
18 changes: 16 additions & 2 deletions lesson_10/README.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"))
}
}


Original file line number Diff line number Diff line change
@@ -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;
@@ -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) {
Loading

0 comments on commit fd6d3e6

Please sign in to comment.