Program Description

Suggested Class Diagram: See image.

Write a Java program that constructs an Applet. Your program should provide labels and textfields to a user to enter information regarding books.

The Applet (JApplet) of your program should contain two tabs. The first tab is labeled "Book creation" and the second tab is labeled "Book review".

(The size of the applet here is approximately 650 X 350).

The section under the first tab should be divided into two parts:

The left part contains labels, textfields, and a button for a user to enter some book information. The right part shows "No book" at the beginning (it is done using JTextArea).

A user can enter some bank information, and push "Create a book" button.

Then the book information should appear on the right hand side panel (note that the format of the book information can be using toString() method of the Book class). A message "Book added" should also appear with red color at the top of the panel.

Error handling:

1. If a user forgets to enter some field and pushes "Create a book" button, show a message "Please fill both title and publisher" with red color, and nothing should be added to the right hand side panel.

After entering several books, the applet will have the following appearance.

Under the "Book review" tab, a user can choose a book to give a rating/review. There should be a JList containing all books created by Book creation panel and a user can choose a book within it by clicking it. Below the JList, there should be five JRadioButtons that represent ratings including, 1. Poor, 2. Fair, 3. Average, 4. Good, and 5. Excellent. Below these radio buttons, there should be a button to confirm a rating the user.

The list of books in the JList should be exactly same as the list under "Book creation" tab. A user can choose a book and its rating, then push " Submit Review " button.

After pushing the button, it should update the rating of the book as follows. Now the rating for the book is listed as 3.0 and the number of review is 1 (within parentheses).

Another user can rate the same book again, then push "Submit Review" button. Since the rating 4 was chosen, now the average rating of the book is 3.50 (= (3+4)/2) with the number of reviews being 2.

Another user can give ratings for other books as well.

A user should be able to go back and forth between "Book creation" tab and "Book review" tab, and these two panels need to have consistent information, i.e., the same list of books. Note that the list of books created in the CreatePanelneeds to be consistent in the list in ReviewPanel, but the averages and the number of reviews updated in theReviewPanel do not need to be reflected in CreatePanel.

Class description

ReviewPanel

ReviewPanel class extends JPanel defined in javax.swing package. It should contain at least the following instance variable:

Attribute name Attribute type Description
bookList Vector a list of bank objects.

This class should have a constructor:

public ReviewPanel(Vector bookList)

where the parameter "bookList" is passed from the Assignment6 class. The constructor layouts and organizes components in this panel. You will be adding more variables (components) than what is listed here, including JList,JRadioButtons, labels, and a button. The JList should be instantiated using the "bookList" vector. Then whenever the vector is updated, the JList will be updated as well by calling its updateUI() method. They will utilize the toString( ) method of the Book class to display each item.

public void updateBookList()

This method calls updateUI() method for the JList that you will be creating. You need to instantiate your JList using thebookList in the constructor. The bookList will be constantly updated under the "Book creation" tab and when it is updated, this method should be called from the actionPerformed method in the ButtonListener of the CreatePanel class so that the JList under the "Book review" will have the same update book list in them.

This class contains a nested class called ButtonListener class that implements ActionListener interface. Thus you need to define its actionPerformed method that is supposed to update the balances and display them when the "Submit Review" button is pushed.

CreatePanel

CreatePanel extends JPanel defined in the javax.swing package. It should contain at least the following instance variable:

Attribute name Attribute type Description
bookList Vector a list of Book objects.
reviewPanel ReviewPanel an object of ReviewPanel.

This class should have a constructor:

public CreatePanel(Vector bookList, ReviewPanel reviewPanel)

where the parameter "bookList" is passed from the Assignment6 class and the second parameter is an object ofReviewPanel. The constructor layouts and organizes components in this panel. You will be adding more variables (components) than what is listed here, including labels, textfields, a button, and a text area.

This class contains a nested class called ButtonListener class that implements ActionListener interface. Thus theButtonListener needs to have a definition for actionPerformed method that adds some bank information to the list and does error handling. See the UML class diagram for the parameter and return type of this method. In theactionPerformed, you need to extract the information from the two textfields for the title and publisher. Then you can instantiate an object of the Book class using the information. You can use the toString( ) method of the Book object to display the information on the textarea on the right hand side and also add the Book object to the "bookList".

Assignment6 class

Assignment6 class extends JApplet defined in javax.swing package. It contains at least init() method (see UML diagram for its return type) to instantiate all instance variables and adds its components to itself. It also sets its size. It contains at least following instance variables:

Attribute name Attribute type Description
bookList Vector a list of book objects. It will be used in both createPanel and reviewPanel.
reviewPanel ReviewPanel an object of ReviewPanel.
createPanel CreatePanel an object of CreatePanel.
tPane JTabbedPane an object of JTabbedPane. It will contain createPanel and reviewPanel under each tab.
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.