Skip to content

Adding analyzer feedback for karls language concept exercise #2722

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

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
],
"prerequisites": [
"arrays",
"for-loops",
"strings"
],
"status": "active"
Expand Down
17 changes: 9 additions & 8 deletions exercises/concept/karls-languages/.docs/hints.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these hints may give away a bit too much. Based on the documentation I'd say they could be just a little bit more cryptic. For example, instead of

Try using the isEmpty() method.

it might say

One of the methods on the List type can be used to check if it is empty.

Same for the other hints.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 15 additions & 1 deletion exercises/concept/karls-languages/.meta/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
public class LanguageList {
private final List<String> languages = new ArrayList<>();

public boolean isEmpty() {
public boolean checkIfEmpty() {
return languages.isEmpty();
}

Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
public class LanguageList {
private final List<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +31,7 @@ public void removeLanguage() {
languageList.addLanguage("Java");
languageList.removeLanguage("Java");

assertThat(languageList.isEmpty()).isTrue();
assertThat(languageList.checkIfEmpty()).isTrue();
}

@Test
Expand Down