This commit is contained in:
femsci 2024-05-23 15:21:25 +02:00
parent 3ffc40596a
commit 8d7dcb22f9
Signed by: femsci
GPG key ID: 08F7911F0E650C67
5 changed files with 111 additions and 1 deletions

View file

@ -1,5 +1,5 @@
# PPJ # 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) [Go back to main](/femsci/ppj/src/branch/nya)

29
dev/meowmeow/Book.java Normal file
View file

@ -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;
}
}

26
dev/meowmeow/Library.java Normal file
View file

@ -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();
}
}

View file

@ -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"));
}
}

26
dev/meowmeow/Shelf.java Normal file
View file

@ -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;
}
}