Final answer:
The MyBookShelf class holds Book objects and manages the addition of new books with the add book method, while keeping track of the number with bookCount. If there is space, a book is added; if not, 'Sorry, the shelf is full' is printed.
Step-by-step explanation:
Implementing the MyBookShelf Class
To create a class MyBookShelf that holds an array of Book instances, we start by defining two private instance variables: catalog, which is an array of Book objects with a fixed length of 10, and bookCount, an integer that tracks the number of books currently on the shelf. The class includes a method add book that takes a book's title and author as parameters. When invoked, this method checks if bookCount is less than 10, indicating there is space on the shelf. If there is room, it creates a new Book instance with the provided title and author, adds it to the catalog array, and increments bookCount by 1. If the shelf is full, meaning bookCount is 10 or more, the method prints out "Sorry, the shelf is full." By managing books this way, the MyBookShelf class mimics a real-world bookshelf with a limited capacity, helping students learn about object-oriented programming and array management in a practical context.