Skip to content

Commit 004b7f8

Browse files
committed
Solution for the Karl's Languages Problem on Exercism.
Instructions: Karl wants to keep track of a list of languages to learn on Exercism's website. Karl needs to be able to add new languages, remove old ones and check if certain languages are in the list. It would be very exciting if Karl wants to learn Java or Kotlin!
1 parent c919dab commit 004b7f8

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

exercises/concept/karls-languages/src/main/java/LanguageList.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,37 @@ public class LanguageList {
55
private final List<String> languages = new ArrayList<>();
66

77
public boolean isEmpty() {
8-
throw new UnsupportedOperationException("Please implement the isEmpty() method");
8+
//throw new UnsupportedOperationException("Please implement the isEmpty() method");
9+
return languages.isEmpty();
910
}
1011

1112
public void addLanguage(String language) {
12-
throw new UnsupportedOperationException("Please implement the addLanguage() method");
13+
// throw new UnsupportedOperationException("Please implement the addLanguage() method");
14+
languages.add(language);
1315
}
1416

1517
public void removeLanguage(String language) {
16-
throw new UnsupportedOperationException("Please implement the removeLanguage() method");
18+
// throw new UnsupportedOperationException("Please implement the removeLanguage() method");
19+
languages.remove(language);
1720
}
1821

1922
public String firstLanguage() {
20-
throw new UnsupportedOperationException("Please implement the firstLanguage() method");
23+
// throw new UnsupportedOperationException("Please implement the firstLanguage() method");
24+
return languages.getFirst();
2125
}
2226

2327
public int count() {
24-
throw new UnsupportedOperationException("Please implement the count() method");
28+
// throw new UnsupportedOperationException("Please implement the count() method");
29+
return languages.size();
2530
}
2631

2732
public boolean containsLanguage(String language) {
28-
throw new UnsupportedOperationException("Please implement the containsLanguage() method");
33+
// throw new UnsupportedOperationException("Please implement the containsLanguage() method");
34+
return languages.contains(language);
2935
}
3036

3137
public boolean isExciting() {
32-
throw new UnsupportedOperationException("Please implement the isExciting() method");
38+
// throw new UnsupportedOperationException("Please implement the isExciting() method");
39+
return languages.contains("Java") || languages.contains("Kotlin");
3340
}
3441
}

0 commit comments

Comments
 (0)