diff --git a/bin/uebung08/doc/Book.class b/bin/uebung08/doc/Book.class new file mode 100644 index 0000000..7d5e4a7 Binary files /dev/null and b/bin/uebung08/doc/Book.class differ diff --git a/bin/uebung08/doc/BookDemo.class b/bin/uebung08/doc/BookDemo.class new file mode 100644 index 0000000..7ea6d41 Binary files /dev/null and b/bin/uebung08/doc/BookDemo.class differ diff --git a/bin/uebung08/doc/Image.class b/bin/uebung08/doc/Image.class new file mode 100644 index 0000000..47f595c Binary files /dev/null and b/bin/uebung08/doc/Image.class differ diff --git a/bin/uebung08/doc/Paragraph.class b/bin/uebung08/doc/Paragraph.class new file mode 100644 index 0000000..1357da9 Binary files /dev/null and b/bin/uebung08/doc/Paragraph.class differ diff --git a/bin/uebung08/doc/Section.class b/bin/uebung08/doc/Section.class new file mode 100644 index 0000000..3fdefa8 Binary files /dev/null and b/bin/uebung08/doc/Section.class differ diff --git a/bin/uebung08/doc/TextComponent.class b/bin/uebung08/doc/TextComponent.class new file mode 100644 index 0000000..b029aac Binary files /dev/null and b/bin/uebung08/doc/TextComponent.class differ diff --git a/src/uebung08/doc/Book.java b/src/uebung08/doc/Book.java new file mode 100644 index 0000000..ae82e76 --- /dev/null +++ b/src/uebung08/doc/Book.java @@ -0,0 +1,37 @@ +package uebung08.doc; + +import java.util.List; + +public class Book { + + private String title; + private String author; + + List content; + + public Book(String author, String title, List content) { + this.author = author; + this.title = title; + this.content = content; + } + + public int countWords() { + int wordcount = 0; + for (TextComponent textComponent : content) { + wordcount += textComponent.countWords(); + } + return wordcount; + } + + public String toText() { + return ""; + } + + public String tableOfContents() { + return ""; + } + + public int countWordsByVisitor() { + return 0; + } +} diff --git a/src/uebung08/doc/BookDemo.java b/src/uebung08/doc/BookDemo.java new file mode 100644 index 0000000..5645f2b --- /dev/null +++ b/src/uebung08/doc/BookDemo.java @@ -0,0 +1,148 @@ +package uebung08.doc; + +import java.util.List; + +public class BookDemo { + private static final String TEXT0 = "Über Entwurf und Realisierung eierlegender Wollmilchsäue."; + private static final String TEXT1 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod " + + "tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. " + + "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd " + + "gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum " + + "dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor " + + "invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."; + private static final String TEXT2 = "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie " + + "consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan " + + "et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis " + + "dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer " + + "adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore " + + "magna aliquam erat volutpat."; + private static final String TEXT3 = "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit " + + "lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure " + + "dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore " + + "eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim " + + "qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla " + + "facilisi."; + private static final String TEXT4 = "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming " + + "id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, " + + "consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet " + + "dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud " + + "exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo " + + "consequat."; + private static final String TEXT5 = "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie " + + "consequat, vel illum dolore eu feugiat nulla facilisis."; + private static final String TEXT6 = "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, " + + "no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, " + + "consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et " + + "dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo " + + "duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est " + + "Lorem ipsum dolor sit amet."; + private static final String TEXT7 = "Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore " + + "et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et " + + "justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata " + + "sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur " + + "sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore " + + "magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo " + + "dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est " + + "Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing " + + "elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam " + + "erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea " + + "rebum. Stet clita kasd gubergren, no sea takimata sanctus."; + private static final String TEXT8 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy " + + "eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam " + + "voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet " + + "clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit " + + "amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam " + + "nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed " + + "diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet " + + "clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. "; + private static final String TEXT9 = "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie " + + "consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan " + + "et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis " + + "dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer " + + "adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore " + + "magna aliquam erat volutpat."; + private static final String TEXT10 = "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit " + + "lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure " + + "dolor in hendrerit in vulputate velit esse molestie consequat, vel illum " + + "dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio " + + "dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te " + + "feugait nulla facilisi."; + private static final String TEXT11 = "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet " + + "doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, " + + "consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut " + + "laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, " + + "quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex " + + "ea commodo"; + private static final String TEXT12 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy " + + "eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam " + + "voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet " + + "clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit " + + "amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam " + + "nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed " + + "diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet " + + "clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; + private static final String TEXT13 = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy " + + "eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam " + + "voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita " + + "kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; + private static final String TEXT14 = "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, " + + "no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit " + + "amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut " + + "labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam " + + "et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata " + + "sanctus est Lorem ipsum dolor sit amet."; + private static final String TEXT15 = "Lorem ipsum dolor sit amet, consetetur sadipscing " + + "elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et " + + "nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd " + + "magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum " + + "dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed " + + "diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat."; + + public static void main(String[] args) { + final Book book = makeBook(); + + // Aufgabe 1 + System.out.println("Buch enthält " + book.countWords() + " Wörter"); + + // Aufgabe 2 + System.out.println("Buch enthält " + book.countWordsByVisitor() + " Wörter"); + System.out.println("Inhalt: " + book.tableOfContents()); + System.out.println(book.toText()); + } + + private static Book makeBook() { + final Section sec1 = new Section("Einführung", + List.of(new Paragraph(TEXT1), + new Paragraph(TEXT2))); + final Section sec2 = new Section("Hintergrund", + List.of(new Paragraph(TEXT3), + new Section("Geschichte", + List.of(new Paragraph(TEXT4), + new Image("https://www.bekannt.de/p1.pdf", + "Bild 1"), + new Paragraph(TEXT5))), + new Section("Literatur", + List.of(new Paragraph(TEXT6), + new Image("https://www.eh-klar.de/p2.pdf", + "Bild 2"), + new Paragraph(TEXT7), + new Image("https://www.jeder-weiss-es.de/p3.pdf", + "Bild 3"), + new Paragraph(TEXT8))))); + final Section sec3 = new Section("Idee", + List.of(new Paragraph(TEXT9))); + final Section sec4 = new Section("Umsetzung", + List.of(new Paragraph(TEXT10), + new Section("Entwurf", + List.of(new Paragraph(TEXT11), + new Section("Grobentwurf", + List.of(new Paragraph(TEXT12))), + new Section("Feinentwurf", + List.of(new Paragraph(TEXT13))))), + new Section("Realisierung", + List.of(new Paragraph(TEXT14))))); + final Section sec5 = new Section("Zusammenfassung und Ausblick", List.of(new Paragraph(TEXT15))); + return new Book("Peter Mustermann", "Die eierlegende Wollmilchsau", + List.of(new Paragraph(TEXT0), sec1, sec2, sec3, sec4, sec5)); + } +} diff --git a/src/uebung08/doc/Image.java b/src/uebung08/doc/Image.java new file mode 100644 index 0000000..7b63d53 --- /dev/null +++ b/src/uebung08/doc/Image.java @@ -0,0 +1,22 @@ +package uebung08.doc; + +public class Image implements TextComponent { + + private String url; + private String caption; + + public Image(String url, String caption) { + this.url = url; + this.caption = caption; + } + + public int countWords() { + return 0; + } + + @Override + public boolean accept(CountWordsVisitor visitor) { + return visitor.visit(this); + } + +} diff --git a/src/uebung08/doc/Paragraph.java b/src/uebung08/doc/Paragraph.java new file mode 100644 index 0000000..ce20b69 --- /dev/null +++ b/src/uebung08/doc/Paragraph.java @@ -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; + } +} diff --git a/src/uebung08/doc/Section.java b/src/uebung08/doc/Section.java new file mode 100644 index 0000000..ad312ee --- /dev/null +++ b/src/uebung08/doc/Section.java @@ -0,0 +1,23 @@ +package uebung08.doc; + +import java.util.List; + +public class Section implements TextComponent { + + private String header; + private List content; + + public Section(String header, List content) { + this.header = header; + this.content = content; + } + + public int countWords() { + int wordcount = 0; + for (TextComponent textComponent : content) { + wordcount += textComponent.countWords(); + } + return wordcount; + } + +} diff --git a/src/uebung08/doc/TextComponent.java b/src/uebung08/doc/TextComponent.java new file mode 100644 index 0000000..130430e --- /dev/null +++ b/src/uebung08/doc/TextComponent.java @@ -0,0 +1,7 @@ +package uebung08.doc; + +public interface TextComponent { + public int countWords(); + + public boolean accept(Visitor visitor); +}