Question: --Write a class Book characterized by the public attributes title a String that represents the title of the book. authors is a Linked List of

--Write a class Book characterized by the public attributes

title a String that represents the title of the book.

authors is a Linked List of String object that stores all the authors names.

price is a double that represents the cost of the book.

The class Book has a constructor that initializes the list authors to an empty linked list,

initializes title to Not Available and the price to 0.

The class Book is comparable and defines a natural ordering based on the price attribute.

The class Book has a toString () method that returns the following String representation:

[title, authors, price]

--Write the method displayAuthors() that displays the list of authors attribute of the class Book. Use an iterator in this method.

The output should be as follow:

Authors for book: title

Author 1: author1 in the list

Author 2: author2 in the list

Example. For a book with Title Java Programming and a list of authors Anis Koubaa, Basit Qurashi, Omar Ghalem:

Authors for book: Java Programming

Author 1: Anis Koubaa

Author 2: Basit Qurashi

Author 3: Omar Ghalem

--Using the above classes definition, write a class BookTest that

1. Creates the two following books:

a. Book 1: Title Java Programming I, a list of authors Basit Qurashi, Omar

Ghalem, and Price 150.00;

b. Book 2: Title Java Programming II and a list of authors Anis Koubaa, Price:

120.00.

2. Create a Set of books called bookSet as TreeSet();

3. Print the content of the bookSet using enhanced for statement;

4. Add the two books in the Tree Set;

5. Display the list authors of the two books.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!