Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the implementations of various classes in a bookStore, We consider a database that stores information about books and owners. Each book has (e.g., String

Complete the implementations of various classes in a bookStore, We consider a database that stores information about books and owners. Each book has (e.g., String title, int price, int yearPublished), whereas BookStoreOwner has (String name and long id). You must implement all methods in the BookStore. For this question, you are required to submit Java files such as Book, BookStore, BookStoreOwner, SortBooksbyYear in your Eclipse

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.*; public class BookStore { /* * YOU NEED A FIELD HERE TO HOLD THE Book OF THIS BookStore */

private TreeMap books; private BookStoreOwner owner;

/** * 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) { // COMPLETE THIS

}

/** * 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) { // COMPLETE THIS

}

/** * 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

}

/** * Adds the specified books to this book store. * * @param books a list of books to add to this book store */ public void add(List books) { // COMPLETE THIS

}

/** * 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

}

/** * 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 sellingBooks(BookStoreOwner user, int pricevalue) {

// COMPLETE THIS

}

image text in transcribed

image text in transcribed

image text in transcribed

  • Returns:

    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

  • image text in transcribed

  • image text in transcribed

  • image text in transcribed

  • image text in transcribed

  • image text in transcribed

    • Returns:

      a string representation of this book store owner

getOwner public BookStoreOwner getowner() 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)! Returns: the owner of this book store change Owner public void changeOwner (BookStoreOwner currentowner, BookStoreOwner newOwner) Allows the current owner of this book store to give this book store to a new owner. Parameters: currentowner - the current owner of this book store newOwner - the new owner of this book store Throws: java.lang. IllegalArgumentException - if currentowner reference is not the reference of the current owner of this book store add public void add (java.util.List books) Adds the specified books to this book store. Parameters: books - a list of books to add to this book store contains public boolean contains (Book book) Returns true if this book store contains the specified book, and false otherwise. Parameters: book - a book Returns: true if this book store contains the specified book, and false otherwise public Book sellingsingleBook (BookStoreowner user, Book book) 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. Parameters: user - the person trying to sell the book book - a book Returns: 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 sellingBooks public java.util.List sellingBooks (BookStoreOwner user, int pricevalue) 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. Parameters: user - the person trying to sell books from this book store pricevalue - a value in dollars Book public Book ) Default Constructor Initialized the book with default value Book public Book (java.lang.String title, int yearPublished, double price) custom constructor Initializes this book to have specific values for its fields Parameters: title - the book title year Published - the year of book title price - price of this book Book public Book (Book book) Copy constructor Initializes this book to have the same fields as the specified book. Parameters: book - : the book that you need to copy getyearPublished public int getyearPublished() Returns the year (yearPublished) field value Returns: the year published field value of this book gettitle public java.lang.String gettitle() Returns the title (title) field value Returns: the title field value of this book getPrice public double getPrice () Returns the price value of this book. Returns: the price value of this book public java.lang.String toString() Returns a string describing this book. The returned string is one of (title, year published, numbe pages, price). Overrides: toString in class java.lang.Object Returns: a string representation of this book hashCode public int hashCode () Returns a hash code for this book. Overrides: hashCode in class java.lang.Object equals public boolean equals(java.lang.Object obj) Compares this book to another book returning true if and only if the specified object is a book with the sam of pages and price values as this book. Overrides: equals in class java.lang. Object Parameters: obj - the object to compare to this book Returns: true if obi is a book with the same values as this book, and false otherwise public BookStoreOwner (java.lang.String name) Initialize this bookstore owner to have the given name and identification number. Parameters: name - the non-null name of this book store owner Method Detail getID public long getID() Returns the unique identification number assigned to this book store owner. Returns: the unique identification number assigned to this book store owner getName public java.lang.String getName() Returns the name of this book store owner. Returns: the name of this book store owner public int hashCode () Returns a hash code for this book store owner. Overrides: hashCode in class java.lang. Object Returns: a hash code for this book store owner equals public boolean equals(java.lang.Object obj) Compares two book store owners for equality. Returns true if obj is a non-null book store owner reference having an identification number equal to the identification number of this book store owner, and false otherwise. Overrides: equals in class java.lang.Object Returns: true if obj is a non-null book store owner reference having an identification number equal to the identification number of this book store owner, and false otherwise to String public java.lang.String toString() Returns a string representation of this book store owner. The string contains the owner name and owner id of this book store owner. Overrides: toString in class java.lang. Object getOwner public BookStoreOwner getowner() 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)! Returns: the owner of this book store change Owner public void changeOwner (BookStoreOwner currentowner, BookStoreOwner newOwner) Allows the current owner of this book store to give this book store to a new owner. Parameters: currentowner - the current owner of this book store newOwner - the new owner of this book store Throws: java.lang. IllegalArgumentException - if currentowner reference is not the reference of the current owner of this book store add public void add (java.util.List books) Adds the specified books to this book store. Parameters: books - a list of books to add to this book store contains public boolean contains (Book book) Returns true if this book store contains the specified book, and false otherwise. Parameters: book - a book Returns: true if this book store contains the specified book, and false otherwise public Book sellingsingleBook (BookStoreowner user, Book book) 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. Parameters: user - the person trying to sell the book book - a book Returns: 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 sellingBooks public java.util.List sellingBooks (BookStoreOwner user, int pricevalue) 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. Parameters: user - the person trying to sell books from this book store pricevalue - a value in dollars Book public Book ) Default Constructor Initialized the book with default value Book public Book (java.lang.String title, int yearPublished, double price) custom constructor Initializes this book to have specific values for its fields Parameters: title - the book title year Published - the year of book title price - price of this book Book public Book (Book book) Copy constructor Initializes this book to have the same fields as the specified book. Parameters: book - : the book that you need to copy getyearPublished public int getyearPublished() Returns the year (yearPublished) field value Returns: the year published field value of this book gettitle public java.lang.String gettitle() Returns the title (title) field value Returns: the title field value of this book getPrice public double getPrice () Returns the price value of this book. Returns: the price value of this book public java.lang.String toString() Returns a string describing this book. The returned string is one of (title, year published, numbe pages, price). Overrides: toString in class java.lang.Object Returns: a string representation of this book hashCode public int hashCode () Returns a hash code for this book. Overrides: hashCode in class java.lang.Object equals public boolean equals(java.lang.Object obj) Compares this book to another book returning true if and only if the specified object is a book with the sam of pages and price values as this book. Overrides: equals in class java.lang. Object Parameters: obj - the object to compare to this book Returns: true if obi is a book with the same values as this book, and false otherwise public BookStoreOwner (java.lang.String name) Initialize this bookstore owner to have the given name and identification number. Parameters: name - the non-null name of this book store owner Method Detail getID public long getID() Returns the unique identification number assigned to this book store owner. Returns: the unique identification number assigned to this book store owner getName public java.lang.String getName() Returns the name of this book store owner. Returns: the name of this book store owner public int hashCode () Returns a hash code for this book store owner. Overrides: hashCode in class java.lang. Object Returns: a hash code for this book store owner equals public boolean equals(java.lang.Object obj) Compares two book store owners for equality. Returns true if obj is a non-null book store owner reference having an identification number equal to the identification number of this book store owner, and false otherwise. Overrides: equals in class java.lang.Object Returns: true if obj is a non-null book store owner reference having an identification number equal to the identification number of this book store owner, and false otherwise to String public java.lang.String toString() Returns a string representation of this book store owner. The string contains the owner name and owner id of this book store owner. Overrides: toString in class java.lang. Object

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions

Question

=+ What does the usage of these products abroad look like?

Answered: 1 week ago