Preface: I'm terrible with java and just learning. Searched a ton, couldn't find an answer. We CANNOT use arraylists.
I have a Book class that contains info in a specific book like pages, author, etc.
I have a Bookshelf class that reads in an array of Book objects. I need to write a method that takes in an author name, finds all the books in the Book array that are by that author, then return an array of those books.
My plan is to find the total number of books by that author and store it in a variable. Then create a new array of that size. I just don't know how to take select elements from the Book array and put them into the new array.
What I have so far, not sure if it's correct...
public Book[] getBooksByAuthor(String author) {
int count = 0;
String a = author;
for(int i = 0; i < books.length; i++){
if(books[i].getAuthor().equals(a)){
count += 1;
}
}
countvariable?