Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please read carefully and follow the instruction: Create the following classes. Use appropriate access modifiers (instance variables should be private!) and data types for each.

Please read carefully and follow the instruction:

Create the following classes. Use appropriate access modifiers (instance variables should be private!) and data types for each. Dont forget to add getter and setter functions.

  1. Item: This class has the attributes (member variables) called title, description, and price.
    • Book: This class inherits from Item Book extends Item. It has an instance variable called pageCount.
    • Movie: This class inherits from Item. Movie extends Item. It has an instance variable called length
    • CD: This class inherits from Item. CD extends Item. It has an instance variable called trackLenght

2.Write a class called Book that contains instance data for the title, description, price, pageCount and copyright date. Define the Book constructor to accept and initialize this data. Include setter and getter methods for all instance data. Override toString() method to returns a nicely formatted, multi-line description of the book. 3.Write another class called Bookshelf, which has a name and array of Book objects. Bookshelf capacity is maximum of five books (do not use an arrayList) . Includes method for Bookself that adds, removes, isFull( returns Boolean), isEmpty(returns Boolean) and toString() method that returns all information about the Books in the Bookshelf. 4. Create a driver class called TestProject, whose main method instantiates five Book objects, two Movie objects and two CD objects. Use a constant name, no need for scanner.

Example:

Book b1 = new Book(Java Book,Laing,200.0,2016,11-20-2020);

Movie x = new Movie(ET,Et was from Jupiter,6.0, 2);

CD cd = new CD(Best,Xcompany,15.0, 120);

.

5.Create an array of Item of size 10.

Item [] ar = new Item[10];

  1. Assign all nine objects created to this array.

7.Use the loop for each to print all element of the array ar.

for(Item aItem : ar)

System.out.println(aItem);

8.Now you have nine objects in the array of ar. Five books, two Movies and two CDs.

9 Use the following loop:

for(int i=0; I < ar.lenght; i++)

{

// try to add books from array ar to Bookshelf array.

// print the book pageCount using getPageCount() method.

// print Movie length using getLength() method.

// print CD trackCount using getTrackCount() method.

}

10 Print Bookshelf content

11 Now create a new book.

Book aNew = new Book((Java Book,Laing,Pearson,200.0,2016);

Add aNew book to the Bookshelf using its add method.

The Bookshelf should print if there is a duplicate.

  1. at last print content of array ar.

Submit Zip File.

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions