Question: Please show the detailed answer using Java, thanks! The following is about creating a class Book and testing it (i) Create a class Book with

Please show the detailed answer using Java, thanks!

Please show the detailed answer using Java, thanks! The following is about

The following is about creating a class Book and testing it (i) Create a class Book with the attributes publisher (which is a string) and weight (an integer) which are used to store the publisher and weight of the book respectively. Write a constructor Book (String publisher, int weight) which assigns the publisher and weight appropriately. Write also the getter/setter methods of the two attributes. Save the content under an appropriate file name. Copy the content of the file as the answers to this part. ii) Create another class Test Book in a separate file with a method main to test the class Book. In main ). create a Book object aBook with publisher "Publisher A" and weight 500. Print the message "A Book object has been created: publisher is Publisher A, weight is 500", in which the data "Publisher A" and "500" are obtained from the corresponding getter method of the attribute. Run the program. Copy the content of the file and the output showing the message as the answers to this part. (iii) Create the class Boo kShop which contains an attribute book which is a Book array. In the constructor BookShop (Book() book), initialize the attribute boo k using the parameter. Also write the getter/setter method of the attribute book. Copy the content of the file as the answers to this part. (iv) Write a method displayBook (int index) of the class BookShop to produce output similar to the following Book number 2 publisher Publisher A weight : 500 where Publisher A is the publisher and 500 is the weight of book, and index has the value 2 The parameter index is the index of the array book. Copy the content of the method as the answers to this part. (v) Add a method publisherCount (String aPublisher) to the class Book Shop which returns the number of books with publisher aPublisher. Copy the content of the method as the answers to this part vi) Add another method heavyBooksto the class BookShop which retums an array with 2 elements containing Book objects with heaviest and second heaviest weights, which are assumed to be unique. Copy the content of the method as the answers to this part. (vii) Create another class TestBoo kShop in a separate file with a method main) to perform the following 1. create a BookShop object myBookShop and initialize it with data for 3 books: ("Publisher A", 500), ("Publisher B", 250), ("Publisher C", 1200); 2. display the book with index 2 using displayBook 3. print the number of books with publisher "Publisher A" 4. print the publisher and weight of the books with top 2 weights; Run the program. Copy the content of the cdass and the output as the answers to this part

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!