Compare commits

...

2 commits
nya ... task/7

Author SHA1 Message Date
8d7dcb22f9
task 7 2024-05-23 15:21:25 +02:00
3ffc40596a
skele 2024-03-28 19:25:56 +01:00
5 changed files with 112 additions and 3 deletions

View file

@ -1,6 +1,5 @@
# PPJ # PPJ
This repository exists to archive PJATK tasks for the PPJ curriculum. This branch contains the solution for the **7th task**.
Each task can be found under its **corresponding branch**: `task/n`. [Go back to main](/femsci/ppj/src/branch/nya)
Example: `task/2`.

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