Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part 1: Write a java class Book which has the following variables: counter: A common variable to all Book's instances, counter's initial value is 0.
Part 1: Write a java class Book which has the following variables: counter: A common variable to all Book's instances, counter's initial value is 0. title: The book title; once it is set, it can't be changed. The default title is "Generic Book". numAvailableCopies: Number of available copies of the book. This variable default initial value is 1. isAvailable: A boolean variable that becomes true if numAvailableCopies > 0, and false otherwise. Add the following methods to the Book class: Overloaded constructors: 1. A no-argument constructor that initializes instance variables to their default valu 2. A constructor that receives two parameters (title, numAvailableCopies) and sets isAvailable accordingly. hint: both constructors must consider counter and isAvailable variables. getTitle, getNumAvailableCopies: Get methods for corresponding instance variables. setNumAvailableCopies: Receives an integer parameter to update numAvailableCopies. isAvailable must be updated accordingly. toString: Returns a string composed from book title, number of available copies and book availability. Part 2: Write a driver class Library with a main method that does the following (in the specified order): 1. Instansiate 1 object of class Book using the default no-argument constructor. 2. Instansiate 2 objects of class Book using the predefined variables (bookTitlei, numCopiesi, bookTitle2, numCopies2). 3. Use method toString to print booki, book2 and book3 information. 4. Update book3 number of available copies to 0. 5. Use method toString to print book3 information. 6. Print the total number of books entered in the system (not the number of available copies)
Step 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