For this problem we will be using inheritance to define a class hierarchy. We will also be making use of the Comparable interface. The overall idea of this assignment, is to design a basic inventory system for a bookstore.

The Inventory Class

  • This class is used to store the inventory of our bookstore. Our bookstore sells only books and cds.
  • This class should be a subclass of ArrayList< Item>. (This may seem weird but it is possible to do, make sure you define the class correctly.) This will mean that your Inventory class will inherit from ArrayList and be able to store instances of the Item class.
  • The class has one constructor which is only there for completion, the constructor does not do anything but create an empty Inventory object.
  • displayAllItems(): should display all of the items in the Inventory class. The output should be intuitive and easy to understand. Use proper spacing and so on.
  • displayAllBooks(): should display ONLY the books in the inventory.
  • displayAllCDs(): should display ONLY the cds in the inventory.
  • reorder(): should display a list of items which have a quantity of 1 by calling each Item's reorder() method.
  • totalCost(): should calculate and return the total cost of all the items in the inventory.

The Item Class

  • Data fields: year (year the item was published), quantity (how many are in stock), price (cost of the item), title (name of the item).
  • provide getters and setters for each of the data fields.
  • This class should have a method called reorder() which is an abstract method with no return values and no parameters.

The Book Class

  • This is a subclass of Item.
  • This class should also implement the Comparable interface. The compareTo() method should be written so that books are sorted according to the Author's last name, first name, and then book title.
  • Data fields: Author (a separate class for the author of the book), number of pages (how many pages the book has), edition (the edition number of the book), publisher (the company that published the book)
  • provide any necessary constructors to initialize your Book. Minimum you need a constructor which initializes all data fields of the Book class (all includes any inherited data fields).
  • Also provide a Copy Constructor which makes a deep copy of a Book.
  • provide getters and setters for each data field.
  • implement the reorder() method from the parent to print out the Title, Author, and publisher of the book.
  • provide a toString method to print a nice representation of the book display all data fields with their respective values. The output should be organized and easy to read. It should look something like:
Title: Harry Potter and the Order of the Phoenix
Author: J.K. Rowling
Year: 2004 etc. etc.....

Again....all data fields must be displayed in a similar, easy-to-read, format.

The CD class

  • This is also a subclass of Item.
  • This class should also implement the Comparable interface. The compareTo() method should be written so that CDs are sorted according to the Artist's last name, first name, and then year the CDs came out.
  • Data fields: Artist (a separate class for the artist of the CD), running length (the running time of the CD (in minutes) ), number of discs (how many discs the CD has), label (the record label that published the CD).
  • provide any necessary constructors to initialize your CD. Minimum you need a constructor which initializes all data fields of the CD class (all includes any inherited data fields).
  • Also provide a Copy Constructor which makes a deep copy of a CD.
  • provide getters and setters for each data field.
  • provide a toString method to display a CD object with output similarly formatted to what a book would be.
  • implement the reorder() method from the parent to display the title, artist and record label of the CD.

The Author Class

  • used as a data field in the Book class
  • data fields: first name, last name
  • Provide any necessary constructors.
  • Provide getters and setters.
  • Provide a toString method to display the Author in a nice format.

The Artist Class

  • used as a data field in the CD class
  • data fields: first name, last name
  • Provide any necessary constructors.
  • Provide getters and setters.
  • Provide a toString method to display the Author in a nice format.

You will also need to provide two separate tester classes.

Tester Class 1:

  • Create an instance of Inventory and populate it with Books and CDs
  • Requirements:
    • at least 5 CD instances
    • at least 5 book instances
    • at least 3 of items (books or cds) must have a quantity of 1 or less
  • Once your Inventory object is populated. Show the output of each of the methods from the Inventory class (only the methods you wrote, NOT the ones inherited from ArrayList).

Tester Class 2:

  • Create two arrays, one array for Books, another for CDs.
  • Populate the arrays with test books and CDs:
  • Requirements:
    • at least 7 CD instances
    • at least 7 Book instance
    • at least 3 of the CDs should have the same artists with different titles and years
    • at least 3 of the books should have the same author with different titles
  • Display each array.
  • Sort each array.
  • Display each array again.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.