implemented composite pattern

This commit is contained in:
2024-06-07 15:25:15 +02:00
parent 41743095bd
commit 753d5e2780
12 changed files with 267 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package uebung08.doc;
public class Paragraph implements TextComponent {
private String text;
public Paragraph(String text) {
this.text = text;
}
public int countWords() {
int wordcount = 0;
boolean isInWord = false;
for (int i = 0; i < text.length(); i++) {
if(Character.isAlphabetic(text.charAt(i))){
if (!isInWord) {
wordcount++;
isInWord = true;
}
} else {
isInWord = false;
}
}
return wordcount;
}
}