0% found this document useful (0 votes)
14 views

Main Java

The document defines a Book class with fields for author, title, and body and getter methods. A Shelf class contains an id, array of Books, and getter methods. A Library class has an array of Shelves and a countAuthor method that counts the number of books by a given author across all shelves.

Uploaded by

Zaden Demario
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Main Java

The document defines a Book class with fields for author, title, and body and getter methods. A Shelf class contains an id, array of Books, and getter methods. A Library class has an array of Shelves and a countAuthor method that counts the number of books by a given author across all shelves.

Uploaded by

Zaden Demario
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

class Book {

private String author;


private String title;
private String body;

public Book(String author, String title, String body) {


this.author = author;
this.title = title;
this.body = body;
}

public String getAuthor() {


return author;
}

public String getTitle() {


return title;
}

public String getBody() {


return body;
}
}

class Shelf {
private String id;
private Book[] books;

public Shelf(String id, Book[] books) {


this.id = id;
this.books = books;
}

public String getId() {


return id;
}

public Book[] getBooks() {


return books;
}
}

class Library {
private Shelf[] shelves;

public Library(Shelf[] shelves) {


this.shelves = shelves;
}

public int countAuthor(String authorName) {


int count = 0;
for (Shelf shelf : shelves) {
Book[] books = shelf.getBooks();
for (Book book : books) {
if (book.getAuthor().equals(authorName)) {
count++;
}
}
}
return count;
}
}

You might also like