Suppose we want to model several different physical bookshelves full of books. W
ID: 3902842 • Letter: S
Question
Suppose we want to model several different physical bookshelves full of books. Which of the following would represent the best structure in Java? a Book class, where each book is an object, and a Shelf class, where each bookshelf is an object a Book class, where each book is an object, and a HashSet of Book objects, where each Set represents a bookshelf a Book class, where each object represents a book along with the details of the shelf it is in a Shelf class, where each object represents the bookshelf and all of its books
Explanation / Answer
a Book class, where each book is an object, and a Shelf class, where each bookshelf is an object a Book class: Here each bookshelf is an object of the Book class. But each bookshelf can contain multiple books and hence each bookshelf cannot be an object of a single book class. So this is a bad model
where each book is an object, and a HashSet of Book objects, where each Set represents a bookshelf : Here each book is a object and a hashset of these objects represent a shelf. However, the hashset doesnot allow multiple similar entries. However a shelf can contain multiple copies of the same book. Hence it is a bad model.
a Book class, where each object represents a book along with the details of the shelf it is in a Shelf class, where each object represents the bookshelf and all of its books : Here the shelf class represents the shelf along with all the books that a shelf has and the individual book class also has the details of the shelf on which it is present. It is the best model to represent the data
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.