From d89f518b155d7ee3f07f94e77e65873f963119fe Mon Sep 17 00:00:00 2001 From: manumafe98 Date: Mon, 5 Feb 2024 17:38:10 -0300 Subject: [PATCH 1/3] Adding analyzer feedback for karls language concept exercise --- config.json | 1 - .../concept/karls-languages/.docs/hints.md | 22 ++++++++++++------- .../concept/karls-languages/.meta/design.md | 15 ++++++++++++- .../src/reference/java/LanguageList.java | 7 +----- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/config.json b/config.json index 7cf0a3dbe..796833bc4 100644 --- a/config.json +++ b/config.json @@ -80,7 +80,6 @@ ], "prerequisites": [ "arrays", - "for-loops", "strings" ], "status": "active" diff --git a/exercises/concept/karls-languages/.docs/hints.md b/exercises/concept/karls-languages/.docs/hints.md index 99eb74775..f27bf46fc 100644 --- a/exercises/concept/karls-languages/.docs/hints.md +++ b/exercises/concept/karls-languages/.docs/hints.md @@ -2,31 +2,37 @@ ## 1. Define a function to check if the language list is empty -- Try using the [`isEmpty()`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#isEmpty()) method. +- Try using the [`isEmpty()`][isempty] method. ## 2. Define a function to add a language to the list -- Try using the [`add(E element)`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#add(E)) method. +- Try using the [`add(E element)`][add] method. - Reminder: methods that return `void` do not need any `return` statements. ## 3. Define a function to remove a language from the list -- Try using the [`remove(Object o)`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#remove(java.lang.Object)) method. +- Try using the [`remove(Object o)`][remove] method. - Reminder: methods that return `void` do not need any `return` statements. ## 4. Define a function to return the first item in the list -- Try using the [`get(int index)`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#get(int)) method. +- Try using the [`get(int index)`][get] method. ## 5. Define a function to return how many languages are in the list -- Try using the [`size()`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#size()) method. +- Try using the [`size()`][size] method. ## 6. Define a function to determine if a language is in the list -- Try using the [`contains(Object o)`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#contains(java.lang.Object)) method. +- Try using the [`contains(Object o)`][contains] method. ## 7. Define a function to determine if the list is exciting -- Try using a [for-each loop](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html) through all of the elements, checking each one. -- Alternatively, try using the `containsLanguage` method from the previous step. +- Try using the `containsLanguage` method from the previous step. + +[isempty]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#isEmpty() +[add]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#add(E) +[remove]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#remove(java.lang.Object) +[get]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#get(int) +[size]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#size() +[contains]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#contains(java.lang.Object) diff --git a/exercises/concept/karls-languages/.meta/design.md b/exercises/concept/karls-languages/.meta/design.md index fac82389e..c4fea43f6 100644 --- a/exercises/concept/karls-languages/.meta/design.md +++ b/exercises/concept/karls-languages/.meta/design.md @@ -43,6 +43,19 @@ This Concepts Exercise's Concepts are: This Concept Exercise's prerequisites Concepts are: -- `for-loops`: know how to use a for-loop to iterate over a collection. - `arrays`: know of the array collection type and that it has a fixed length. - `strings`: data types used in this exercise + +## Analyzer + +This exercise could benefit from the following rules in the [analyzer]: + +- `essential`: If the student did not reuse the implementation of the `containsLanguage` method in the `isExciting` method, instruct them to do so. + Explain that reusing existing code instead of copy-pasting can help make code easier to maintain. +- `actionable`: If the solution did not use `contains` in the method `containsLanguage`, instruct the student to do so. +- `actionable`: If the solution did not use `isEmpty` in the method `isEmpty`, instruct the student to do so. + +If the solution does not receive any of the above feedback, it must be exemplar. +Leave a `celebratory` comment to celebrate the success! + +[analyzer]: https://github.com/exercism/java-analyzer diff --git a/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java b/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java index 963abbcdb..13df5f4a2 100644 --- a/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java +++ b/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java @@ -29,11 +29,6 @@ public boolean containsLanguage(String language) { } public boolean isExciting() { - for (String language : languages) { - if (language.equals("Java") || language.equals("Kotlin")) { - return true; - } - } - return false; + return containsLanguage("Java") || containsLanguage("Kotlin"); } } From d79bbc928613255fa16240d7f5796a8ab5252cd7 Mon Sep 17 00:00:00 2001 From: manumafe98 Date: Mon, 5 Feb 2024 20:54:49 -0300 Subject: [PATCH 2/3] Applying suggestions Update hints to not say exactly what to do Update isEmpty name to one that does not says directly what to apply change the analyzer topic that checks that the students re uses containsLanguage to informative Add an informative topic if the students uses an if statement on containsLanguage --- .../concept/karls-languages/.docs/hints.md | 21 +++++++------------ .../concept/karls-languages/.meta/design.md | 5 +++-- .../src/reference/java/LanguageList.java | 2 +- .../src/main/java/LanguageList.java | 4 ++-- .../src/test/java/LanguageListTest.java | 10 ++++----- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/exercises/concept/karls-languages/.docs/hints.md b/exercises/concept/karls-languages/.docs/hints.md index f27bf46fc..112b935cb 100644 --- a/exercises/concept/karls-languages/.docs/hints.md +++ b/exercises/concept/karls-languages/.docs/hints.md @@ -2,37 +2,32 @@ ## 1. Define a function to check if the language list is empty -- Try using the [`isEmpty()`][isempty] method. +- One of the [methods][list] on the List type can be used to check if it is empty. ## 2. Define a function to add a language to the list -- Try using the [`add(E element)`][add] method. +- One of the [methods][list] on the List type can be used to add elements. - Reminder: methods that return `void` do not need any `return` statements. ## 3. Define a function to remove a language from the list -- Try using the [`remove(Object o)`][remove] method. +- One of the [methods][list] on the List type can be used to remove elements. - Reminder: methods that return `void` do not need any `return` statements. ## 4. Define a function to return the first item in the list -- Try using the [`get(int index)`][get] method. +- One of the [methods][list] on the List type can be used to get elements on a certain index. ## 5. Define a function to return how many languages are in the list -- Try using the [`size()`][size] method. +- One of the [methods][list] on the List type can be used to get the size of the list. ## 6. Define a function to determine if a language is in the list -- Try using the [`contains(Object o)`][contains] method. +- One of the [methods][list] on the List type can be used to check if an element is contained in the list. ## 7. Define a function to determine if the list is exciting -- Try using the `containsLanguage` method from the previous step. +- Try using a method already defined in the class. -[isempty]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#isEmpty() -[add]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#add(E) -[remove]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#remove(java.lang.Object) -[get]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#get(int) -[size]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#size() -[contains]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#contains(java.lang.Object) +[list]: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html diff --git a/exercises/concept/karls-languages/.meta/design.md b/exercises/concept/karls-languages/.meta/design.md index c4fea43f6..5f44a4a67 100644 --- a/exercises/concept/karls-languages/.meta/design.md +++ b/exercises/concept/karls-languages/.meta/design.md @@ -50,10 +50,11 @@ This Concept Exercise's prerequisites Concepts are: This exercise could benefit from the following rules in the [analyzer]: -- `essential`: If the student did not reuse the implementation of the `containsLanguage` method in the `isExciting` method, instruct them to do so. - Explain that reusing existing code instead of copy-pasting can help make code easier to maintain. - `actionable`: If the solution did not use `contains` in the method `containsLanguage`, instruct the student to do so. - `actionable`: If the solution did not use `isEmpty` in the method `isEmpty`, instruct the student to do so. +- `informative`: If the student did not reuse the implementation of the `containsLanguage` method in the `isExciting` method, instruct them to do so. + Explain that reusing existing code instead of copy-pasting can help make code easier to maintain. +- `informative`: If the solution uses an `if statement` in the `containsLanguage` method, instruct the student to return directly the `contains` method. If the solution does not receive any of the above feedback, it must be exemplar. Leave a `celebratory` comment to celebrate the success! diff --git a/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java b/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java index 13df5f4a2..9440b92ee 100644 --- a/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java +++ b/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java @@ -4,7 +4,7 @@ public class LanguageList { private final List languages = new ArrayList<>(); - public boolean isEmpty() { + public boolean checkIfEmpty() { return languages.isEmpty(); } diff --git a/exercises/concept/karls-languages/src/main/java/LanguageList.java b/exercises/concept/karls-languages/src/main/java/LanguageList.java index 0da6b44c7..b8e4dfd7f 100644 --- a/exercises/concept/karls-languages/src/main/java/LanguageList.java +++ b/exercises/concept/karls-languages/src/main/java/LanguageList.java @@ -4,8 +4,8 @@ public class LanguageList { private final List languages = new ArrayList<>(); - public boolean isEmpty() { - throw new UnsupportedOperationException("Please implement the isEmpty() method"); + public boolean checkIfEmpty() { + throw new UnsupportedOperationException("Please implement the checkIfEmpty() method"); } public void addLanguage(String language) { diff --git a/exercises/concept/karls-languages/src/test/java/LanguageListTest.java b/exercises/concept/karls-languages/src/test/java/LanguageListTest.java index 551d6cfc9..87481d5ff 100644 --- a/exercises/concept/karls-languages/src/test/java/LanguageListTest.java +++ b/exercises/concept/karls-languages/src/test/java/LanguageListTest.java @@ -10,18 +10,18 @@ public class LanguageListTest { @Test @Tag("task:1") - @DisplayName("The isEmpty method returns true when the list contains no languages") + @DisplayName("The checkIfEmpty method returns true when the list contains no languages") public void empty() { - assertThat(languageList.isEmpty()).isTrue(); + assertThat(languageList.checkIfEmpty()).isTrue(); } @Test @Tag("task:2") - @DisplayName("The isEmpty method returns false after adding a language to the list") + @DisplayName("The checkIfEmpty method returns false after adding a language to the list") public void nonEmpty() { languageList.addLanguage("Java"); - assertThat(languageList.isEmpty()).isFalse(); + assertThat(languageList.checkIfEmpty()).isFalse(); } @Test @@ -31,7 +31,7 @@ public void removeLanguage() { languageList.addLanguage("Java"); languageList.removeLanguage("Java"); - assertThat(languageList.isEmpty()).isTrue(); + assertThat(languageList.checkIfEmpty()).isTrue(); } @Test From 5f4413e8595ad9a925f4751e5ef321ce82eeebe8 Mon Sep 17 00:00:00 2001 From: manumafe98 Date: Thu, 8 Feb 2024 10:14:25 -0300 Subject: [PATCH 3/3] Rollbacking rename of method isEmpty --- .../.meta/src/reference/java/LanguageList.java | 2 +- .../karls-languages/src/main/java/LanguageList.java | 4 ++-- .../src/test/java/LanguageListTest.java | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java b/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java index 9440b92ee..13df5f4a2 100644 --- a/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java +++ b/exercises/concept/karls-languages/.meta/src/reference/java/LanguageList.java @@ -4,7 +4,7 @@ public class LanguageList { private final List languages = new ArrayList<>(); - public boolean checkIfEmpty() { + public boolean isEmpty() { return languages.isEmpty(); } diff --git a/exercises/concept/karls-languages/src/main/java/LanguageList.java b/exercises/concept/karls-languages/src/main/java/LanguageList.java index b8e4dfd7f..0da6b44c7 100644 --- a/exercises/concept/karls-languages/src/main/java/LanguageList.java +++ b/exercises/concept/karls-languages/src/main/java/LanguageList.java @@ -4,8 +4,8 @@ public class LanguageList { private final List languages = new ArrayList<>(); - public boolean checkIfEmpty() { - throw new UnsupportedOperationException("Please implement the checkIfEmpty() method"); + public boolean isEmpty() { + throw new UnsupportedOperationException("Please implement the isEmpty() method"); } public void addLanguage(String language) { diff --git a/exercises/concept/karls-languages/src/test/java/LanguageListTest.java b/exercises/concept/karls-languages/src/test/java/LanguageListTest.java index 87481d5ff..551d6cfc9 100644 --- a/exercises/concept/karls-languages/src/test/java/LanguageListTest.java +++ b/exercises/concept/karls-languages/src/test/java/LanguageListTest.java @@ -10,18 +10,18 @@ public class LanguageListTest { @Test @Tag("task:1") - @DisplayName("The checkIfEmpty method returns true when the list contains no languages") + @DisplayName("The isEmpty method returns true when the list contains no languages") public void empty() { - assertThat(languageList.checkIfEmpty()).isTrue(); + assertThat(languageList.isEmpty()).isTrue(); } @Test @Tag("task:2") - @DisplayName("The checkIfEmpty method returns false after adding a language to the list") + @DisplayName("The isEmpty method returns false after adding a language to the list") public void nonEmpty() { languageList.addLanguage("Java"); - assertThat(languageList.checkIfEmpty()).isFalse(); + assertThat(languageList.isEmpty()).isFalse(); } @Test @@ -31,7 +31,7 @@ public void removeLanguage() { languageList.addLanguage("Java"); languageList.removeLanguage("Java"); - assertThat(languageList.checkIfEmpty()).isTrue(); + assertThat(languageList.isEmpty()).isTrue(); } @Test