Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please add comments when possible. Objects Lab Write a class Book to model books. This book object will have two instance variables: a title (String)
please add comments when possible.
Objects Lab Write a class "Book" to model books. This book object will have two instance variables: a title (String) and authors (Array of Strings). Write a default constructor which sets title to "Test" and authors to null. Write a constructor receiving values for these fields. Lastly, implement getter and setter methods for your instance variables In "Book", write a method "bookToString", which returns a string with the books information (in the format below. Use " to have a quote character in a string. The Lord of the Rings" by J.R.R. Tolkien "Nixonland" by Rick Perlstein Berenstain Bears" by Stan Berenstain & Jan Berenstain Write a class "Bookshelf" to model a bookshelf. This bookshelf object will have two instance variables: size (int) and books (ArrayList of Books). Write a default constructor which sets the size to 2 and initializes the ArrayList. Write a parameterized constructor which receives a single parameter for size and initializes the ArrayList. Write a getter method for the size instance variable. (Don't write a setter method, you can't change the size of a bookshelf after it's been created!) Write a getter method for the books instance variable. Rather than a single setter method, write three specific methods to modify the contents of the bookshelf: a public void method addBook which takes a single book parameter and adds it to the shelf variable if there is room in the shelf, a public void method removeBook which takes no parameters and removes the first book on the shelf (the book at position 0 in the books ArrayList), and a public void method emptyBookshelf which takes no parameters and removes all of the books from the shelf (empties the books ArrayList) Neither the "Book" class or the "Bookshelf' class can have a main method. If you want to test your "Book" and "Bookshelf classes, you may make a separate class with a main method. You do not need to submit this separate classStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started