Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Library.java This class will represent a university Library that will contain the following private instance variables Book [] books: this will represent the books that
Library.java This class will represent a university Library that will contain the following private instance variables Book [] books: this will represent the books that are within the library. int capacity: this represents the maximum capacity of books a library can have. int size: this represents the number of non-null elements within the books array. This class will also have the following public instance methods void addBook (Book book) o This will add a book to the end of the books array at index size. o If the books array is full, then print out Cannot add book, library is full!" o Be sure to update size as necessary. getters for all instance variables. This class will have the following constructors Library() - this constructor will set capacity to 10 and instantiate the books array to be of length capacity. o You must use constructor chaining to chain this constructor to Library(int capacity). Library (Book[] books) - this constructor will set capacity and size to be the parameter books's length. It will also set the instance variable books equal to the passed in parameter. You may assume that the parameter won't be null, and no books in the array will be null. Library(int capacity) - this constructor will set capacity equal to the passed in capacity as well as instantiate books to be of length capacity Book.java This class will have the following private instance variables: String title - this will represent the title of the book boolean checkedOut - this will represent if a book has been checked out by student or not. int daysUntiloverdue - this represents the number of days a student has to return the book until it becomes overdue. This class will have the following public instance methods String toString() - This should return a string that contains the title of the book. You can format it however you want. getters for all instance variables setters for the checkedout and daysUntiloverdue variables. This class will have the following constructor: Book (String title) - this should set the title to the passed in parameter. Student.java This class will have the following private instance variables: String name - represents the name of the student. Book book - represents the book the student checked out. double debt - represents the debt a student must pay for overdue books. This class will have the following constructor: Student(String name) - this should initialize the student's name with the passed in value. This class will have the following public instance methods String toString() - this method will decrease the number of days until overdue for the book that the student checked out. o If the student has a book, return "You have book title checked out and [days until overdue) days until it's due. o If the student does not have a book, return "You have no library books" void checkOut(Library library) - for this method, you will need to pick a random index and get the book at that index from the Library. Then assign this book to the instance book. o Be sure to set this book as "checkedOut. o If the book is already checked Out, print "This book is already checked out!" and don't assign this to book. o If the library is empty, then print "Sorry, this library is empty.. O Also set the days until due date for the book to be 3 days. void checkOut(int index, Library library) - for this method, you will be checking out a book from the Library at that given index, similar to the checkOut(Library library) method above. However: If the index is greater than size of the library, print out "The library is not that big yet!". If the book at that index is checked out, print out This book is already checked out!" and don't assign it to book. Also set the days until due date for the book to be 3 days. void returnBook () - this method will return a book back to the library. o If the student does not have a book, print out "You have no book to return!". o If the student does have a book, set the book's checkout variable to be false and daysUntiloverdue to 0. However, if the book's daysUntiloverdue is less than 0, then the student must pay a debt of $5. Print out "You will be charged $5 for returning this book late." void payDebt (double pay) - This method should decrease the student's debt by pay. o If the student has no debt, print out You have no debt to pay off. . However, if the pay is greater than the debt, then set debt to 0
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