Question
package bookStore; /** * A class representing a book store that has an * owner . A book store owns a collection (or possibly *
package bookStore;
/** * A class representing a book store that has an * owner . A book store owns a collection (or possibly * collections) of books, but does not own the books themselves * . * *
* Only the owner of the book store is able to sell books from the book store. * The book store does NOT own its owner . *
*/import java.util.*; import bookStore.Book; import bookStore.BookStoreOwner;
public class BookStore { /* * YOU NEED A FIELD HERE TO HOLD THE Book OF THIS BookStore */
private TreeMap
/** * Initializes this book store so that it has the specified owner and no * books. * * @param owner the owner of this book store */ public BookStore(BookStoreOwner owner) { this.owner = owner;
}
/** * Initializes this book store by copying another book store. This book store will * have the same owner and the same number and type of books as the other * book store. * * @param other the book store to copy */ public BookStore(BookStore other) { this.books = other.books; this.owner = other.owner;
}
/** * Returns the owner of this book store. * *
* This method is present only for testing purposes. Returning the owner of this * book store allows any user to sell books from the book store (because any * user can become the owner of this book store)! * * @return the owner of this book store */ public BookStoreOwner getOwner() { // ALREADY IMPLEMENTED; DO NOT MODIFY return this.owner; }
/** * Allows the current owner of this book store to give this book store to a new * owner. * * @param currentOwner the current owner of this book store * @param newOwner the new owner of this book store * @throws IllegalArgumentException if currentOwner reference is not the reference of the * current owner of this book store */ public void changeOwner(BookStoreOwner currentOwner, BookStoreOwner newOwner) {
// COMPLETE THIS if (currentOwner != this.getOwner()) { throw new IllegalArgumentException(); } currentOwner.setName(newOwner.getName()); currentOwner.setId(newOwner.getId()); }
/** * Adds the specified books to this book store. * * @param books a list of books to add to this book store */ public void add(List
/** * Returns true if this book store contains the specified book, and false * otherwise. * * @param book a book * @return true if this book store contains the specified book, and false * otherwise */ public boolean contains(Book book) {
// COMPLETE THIS if (books.containsKey(book)==true) { return true; } return false; }
/** * Allows the owner of this book store to sell a single book equal to the * specified book from this book store. * *
* If the specified user is not equal to the owner of this book store, then the * book is not sold from this book store, and null is returned. * * @param user the person trying to sell the book * @param book a book * @return a book equal to the specified book from this book store, or null * if user is not the owner of this book store @pre. the book store * contains a book equal to the specified book */ public Book sellingsingleBook(BookStoreOwner user, Book book) {
// COMPLETE THIS
}
/** * Allows the owner of this book store to sell the smallest number of books * whose total price value in dollars is equal or less than to the specified * price value in dollars. Try from the most expensive book and you may want * to use descendingKeySet() method. * *
* Returns the empty list if the specified user is not equal to the owner of * this book store. *
* * @param user the person trying to sell books from this book store * @param pricevalue a value in dollars * @return the smallest number of books whose total price value in dollars is * equal to the specified value in dollars from this book store @pre. the * book store contains a group of books whose total price value is * equal to specified value */ public List// COMPLETE THIS
} }
* Adds the specified books to this book store. * @param books a list of books to add to this book store */ public void add(List
* If the specified user is not equal to the owner of this book store, then the book is not sold from this book store, and null is returned. * @param user the person trying to sell the book * @param book a book * @return a book equal to the specified book from this book store, or null if user is not the owner of this book store @rre. the book store contains a book equal to the specified book * public Book sellingsingleBook (BookStoreOwner.usec Book book) { // COMPLETE THIS * Allows the owner of this book store to sell the smallest number of books e in dollars is equal or less than to the specified * price value in dollars. Try from the most expensive book and you may want * to use descendingKeySet() method. *
* Returns the empty list if the specified user is not equal to the owner of * this book store. *
* @param user the person trying to sell books from this book store * @param pricevalue a value in dollars * @return the smallest number of books whose total price value in dollars is equal to the specified value in dollars from this book store @rre. the book store contains a group of books whose total price value is equal to specified value public ListStep 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