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..112b935cb 100644 --- a/exercises/concept/karls-languages/.docs/hints.md +++ b/exercises/concept/karls-languages/.docs/hints.md @@ -2,31 +2,32 @@ ## 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. +- 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)`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#add(E)) 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)`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#remove(java.lang.Object)) 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)`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#get(int)) 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()`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#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)`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/List.html#contains(java.lang.Object)) 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 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 a method already defined in the class. + +[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 fac82389e..5f44a4a67 100644 --- a/exercises/concept/karls-languages/.meta/design.md +++ b/exercises/concept/karls-languages/.meta/design.md @@ -43,6 +43,20 @@ 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]: + +- `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! + +[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"); } }