diff --git a/README.md b/README.md index a4b6575..0114b52 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # PPJ -This branch contains the solution for the **nth task**. +This branch contains the solution for the **7th task**. [Go back to main](/femsci/ppj/src/branch/nya) diff --git a/dev/meowmeow/Book.java b/dev/meowmeow/Book.java new file mode 100644 index 0000000..d7878cc --- /dev/null +++ b/dev/meowmeow/Book.java @@ -0,0 +1,29 @@ +/* + * TASK 7 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/7 + * by femsci + */ + +package dev.meowmeow; + +public class Book { + public Book(String author, String title, String body) { + this.author = author; + this.title = title; + this.body = body; + } + + private final String author, title, body; + + public String getBody() { + return body; + } + + public String getTitle() { + return title; + } + + public String getAuthor() { + return author; + } +} diff --git a/dev/meowmeow/Library.java b/dev/meowmeow/Library.java new file mode 100644 index 0000000..11b1836 --- /dev/null +++ b/dev/meowmeow/Library.java @@ -0,0 +1,26 @@ +/* + * TASK 7 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/7 + * by femsci + */ + +package dev.meowmeow; + +import java.util.Arrays; + +public class Library { + public Library(Shelf[] shelves) { + this.shelves = shelves; + } + + private final Shelf[] shelves; + + public Shelf[] getShelves() { + return shelves; + } + + public int countAuthor(String author) { + return (int) Arrays.asList(shelves).stream().flatMap(x -> Arrays.stream(x.getBooks())) + .filter(f -> f.getAuthor().equals(author)).count(); + } +} diff --git a/dev/meowmeow/Nyaaaaaa.java b/dev/meowmeow/Nyaaaaaa.java new file mode 100644 index 0000000..e3cf653 --- /dev/null +++ b/dev/meowmeow/Nyaaaaaa.java @@ -0,0 +1,29 @@ +/* + * TASK 7 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/7 + * by femsci + */ + +package dev.meowmeow; + +public class Nyaaaaaa { + + public static void main(String[] args) { + Shelf sh1 = new Shelf("Shelf1", + new Book[] { + new Book("Babel", "Odessa Tales", "babelode"), + new Book("Joyce", "Ulisses", "joyceuli") + }); + + Shelf sh2 = new Shelf("Shelf2", + new Book[] { + new Book("Mann", "Dr Faustus", "mannfau"), + new Book("Babel", "Red Cavalry", "babelred") + }); + + Library lib = new Library(new Shelf[] { sh1, sh2 }); + + System.out.printf("# of books by this author: %d\n", + lib.countAuthor("Babel")); + } +} diff --git a/dev/meowmeow/Shelf.java b/dev/meowmeow/Shelf.java new file mode 100644 index 0000000..c2906b7 --- /dev/null +++ b/dev/meowmeow/Shelf.java @@ -0,0 +1,26 @@ +/* + * TASK 7 + * archived at https://git.femboy.science/femsci/ppj/src/branch/task/7 + * by femsci + */ + +package dev.meowmeow; + +//final class :3c +public class Shelf { + public Shelf(String id, Book[] books) { + this.id = id; + this.books = books; + } + + private final String id; + private final Book[] books; + + public String getId() { + return id; + } + + public Book[] getBooks() { + return books; + } +}