Question

Minimal Submitted Files

You are required, but not limited, to turn in the following source files:

Assignment4.java
Book.java
Review.java

Requirements to get full credits in Documentation

The assignment number, your name, StudentID, Lecture number(time), and a class description need to be included at the top of each file/class.

A description of each method is also needed. Some additional comments inside of methods (especially for a "main" method) to explain code that are hard to follow should be written. You can look at the Java programs in the text book to see how comments are added to programs.

Skills to be Applied

In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:

Classes
Instance Objects
Accessors/Mutators(Modifiers) methods
Visibility Modifiers (Access specifier) - public, private, etc.
Encapsulation concept
Aggregation relationship between classes
DecimalFormat class in java.text package


Assignment #4 will be the construction of 2 new classes and a driver program (the class containing a main method).


Review class:

The Review class describes the review of a Book. It has following attributes:

Attribute name Attribute type Description
numberOfReviews int the number of Reviews
sumOfRatings double the sum of all ratings
average double the average of ratings
The following constructor should be provided to initialize each attribute:
public Review()

This constructor initializes numberOfReviews to 0 and sumOfRatings and average to 0.0.

The following method should be provided to increase the number of Reviews by 1 and the sum of Rating by adding the parameter rating. If the number of reviews is greater than 0, then its average (rating) needs to be computed. Otherwise, the average should be set to 0.0.
public void updateRating(double rating)

The following method must be defined:

public String toString()

The toString() method constructs a string of the following form:
Reviews:t0.00(0)

where 0.00 is the average (only two digits after the decimal point should be shown - use DecimalFormat class) and 0 within the parenthesis is the number of reviews. Note that the average and the number of reviews can be changed to some other values.


Book class:

The Book class describes a book that a customer can give a review/rating. It must have the following attributes:

Attribute name Attribute type Description
title String The title of the Book
publisher String The publisher of the Book
bookReview Review The review of the Book

The following constructor should be provided to initialize each attribute:
public Book()

This constructor initializes all strings to "?", and instantiates an object of Review (i.e., call the constructor of the Review class to create an object of Review).

The following accessor methods should be provided to get the attributes:
public String getTitle()
public String getPublisher()
public Review getReview()

The following mutator methods should be provided to change the attributes:
public void setTitle(String aTitle)
public void setPublisher(String aPublisher)
The following mutator method should be provided to change the review. It should call updateRating method of the Review class:

public void addRating(double rate)


The following method must be defined:

public String toString()


The toString() method constructs a string of the following format:

nTitle:tIntroduction to Java Programming,n
Publisher:tPearson,n
Reviews:t0.00(0)nn


You can make use of the DecimalFormat class in java.text package to format the average having two digits after the a decimal point "0.00".

Error Handling:

Your program is expected to be robust to handle seven test cases.


GIVEN THE INPUTS (INPUT1, INPUT2, ETC.) THE PROGRAM SHOULD GIVE THE CORRESPONDING OUTPUTS (OUTPUT1, OUTPUT2, ETC.)

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

// Description: Book class defines the attributes of a book including title, publisher and reviews.
//             It allows user to get and set these attributes

public class Book {

String title;
String publisher;
Review bookReview;

public Book(){
title = "?";
publisher = "?";
bookReview = new Review();
}

//accessor method to get title of book
public String getTitle(){
return title;
}

//accessor method to get publisher of book
public String getPublisher(){
return publisher;
}

//accessor method to get review of the book
public Review getReview(){
return bookReview;
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

ChatBot Using Java Programming
Homework Solution
$7.00
Java
Programming
Coding
Chatting
Bot
Users
Computers
Sentences
Symbols
Instant Messaging
Input
Output
Special Characters
Even Numbers
Odd Numbers
Money Problems in Java
Homework Solution
$20.00
Java
Programming
Codes
Algorithms
Money
Dimes
Nickels
Pennies
Input
Output
Integers
Statements
Variables
Accounting
Recursion Methods
Finance
Java Program For Vending Machine
Homework Solution
$40.00
Java
Programming
Computer Science
Vending Machine
Drinks
Password
Screen
Inventory
Menu
Errors
Money
Pyramid Using Asterisks in Java
Homework Solution
$30.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Strings
Asterisks
Symbols
Pyramid
Rows
Odd Numbers
Get help from a qualified tutor
Live Chats