finished CountWordsVisitor

This commit is contained in:
2024-06-08 12:53:20 +00:00
parent dcf2a95b4f
commit 81ea768dca
6 changed files with 64 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
package uebung08.doc;
import java.util.ArrayList;
import java.util.List;
public class Book {
@@ -28,10 +29,22 @@ public class Book {
}
public String tableOfContents() {
return "";
List<String> res = new ArrayList<>();
for (TextComponent textComponent : content) {
res.addAll(textComponent.accept(new TableOfContentsVisitor()));
}
return res.toString();
}
public int countWordsByVisitor() {
return 0;
int count = 0;
for (TextComponent textComponent : content) {
count += textComponent.accept(new CountWordsVisitor());
}
return count;
}
}