Concepts Utilized in this Project UML diagrams Menu driven p

Concepts Utilized in this Project

UML diagrams

Menu driven program

Java fundamentals, including decision structures, loops

Constructors, Overloaded constructors

toString method

Formatting output with DecimalFormat

Random Class

Java objects & classes

Overview

Write an application that simulates adding new books to the Amazon database.

The Application repeatedly asks the information of a new book and once the information is gathered, it will be displayed to the user. Note that this application does not save the information of the book.

Information of the book includes its title, author, the number of ratings, the sum of all the rating (the rating given to a book is 1 or 2 or 3 or 4), its price and whether the book has a hardcover or not.

When adding a new book, the user can choose to provide only the book title and its author. The rest of the information will be set to default values by the program: Price to random number between 1 and 10, the number of ratings and the sum of ratings to 0 and no hardcover for the book.

The user can also choose to enter all the book’s information.

A book can have 0 or more than one rating. Rating given to a book is a number between 1 (lowest) and 4 (highest). The number of ratings and the total will be saved in the book’s information.

After information is entered for the book, it will be displayed to the user. The program will also display a recommendation information for the book based on its average rating: If the average rating is between 3 and 4, the book is strongly recommended, between 2 and 3 is recommended, between 1 and 2, not recommended and if there is no rating then no information is available for recommendation.

User Operation

Following is a Sample of program run:

                                                                           

Specifications & Requirements

Design and implement a Java application to satisfy the specified high level requirements from the Overview section. The system is required to do the following:

Data Element Class - Book

Create a class with the given information (fields) in the overview section.

Create a constructor that takes book’s title and author and creates a book instance with the provided information. The number of ratings, Total rating will be set to zero, price is set to random number between 1 and 10 and the book has not hardcover.

Create another constructor that takes the information for the title, author, price and whether the book has hardcover or not and creates a book instance with the given information. The number of ratings, Total rating will be set to zero.

A method addRating that takes the rating for the book and adds it to the total rating as well as incrementing the number of ratings for this book.

A method called findAvgRating that returns the average rating for this book or 0 if there is no rating for the book.

A method called bookRecommendation that returns a string based on the average rating of the book. The book is “strongly recommended” for average rating between 3 and 4, “Recommended” for average rating between 2 and 3(exclusive) , “Not Recommended” for average rating between 1 and 2 (exclusive) , and if there is no rating return “No Information Is Available For Recommendation”.

A toString method that returns the string representation of a Book object: title, author, number of ratings, average rating, price and book recommendation.

Add any necessary getter or setter methods.

Driver Class - Amazon

This is the driver class for Book that contains a main method.

Create a method getInput() that returns a Book object. This method allows the user to enter book information, uses the information to construct a Book object and returns it.

This class contains a main method which continues asking the book information as long as user chooses to enter more information and displays the information of the book to the user. Refer to the program sample run for more clarification.

Add any necessary methods to modularize your code.

Welcome to Amazon Book Information Entry Application! Let\'s start entering book information Enter book title: Enter book Author: Harry Potter and the Cursed Child K Rowling OK Cancel OK Cancel Enter Rating (14) or 0 for no rating: Do you have more information for the book, ex. price, type of cover- or n)? Cancel OK Cancel input Enter more Rating (1-4) or 0 for no more rating: Enter more Rating (14) or 0 for no more rating I INVALIDRATING OK Cancel OK Cancel input Enter more Rating (1-4) or 0 for no more rating: Enter Rating (14) or 0 for no rating: Cancel OK Cancel nput i) Following book is added to the Amazon Database TITLE: Harry Potter and The Cursed Child Do you want to enter another book information(y or n) AUTHOR: JK Rowling TOTALNOF RATINGS: 3 AVERAGE RATING: 3.67 OK Cancel PRICE: 7.0 R: no RCOMMENDATION BASEDON BOOKRATINGS: Strongly Recommended

Solution

Book.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Sam
*/
public class Book {
    private String title;
    private String author;
    private int numberOfRatings;
    private int totalRating;
    private float price;
    private boolean hasHardCover;
  
    public Book(String title, String author){
        this.title = title;
        this .author = author;
        numberOfRatings = 0;
        totalRating = 0;
        price = (float) (Math.random()*10);
        hasHardCover = false;
    }
  
    public Book (String title, String author, float price, boolean hasHardCover){
        this.title = title;
        this .author = author;
        numberOfRatings = 0;
        totalRating = 0;
        this.price = price;
        this.hasHardCover = hasHardCover;
    }
  
    public void addRating(int rating){
        totalRating += rating;
        numberOfRatings ++;
    }
  
    public float findAvgRating() {
        if (numberOfRatings == 0)
            return 0;
        return ((float)totalRating)/numberOfRatings;
    }
  
    public String bookRecommendation(){
        float avgRating = findAvgRating();
        if (avgRating>=3 && avgRating<=4)
            return \"Strongly Recomended\";
        if (avgRating >= 2 && avgRating <3)
            return \"Recommended\";
        else if (avgRating >=1 && avgRating<2)
            return \"Not Recommended\";
        else if (avgRating == 0)
            return \"No Information Is Available For Recommendation\";
        return \"UNEXPECTED DAATA FOUND\";          
    }
  
    @Override
    public String toString(){
        return \"Book title: \" + title
                + \"\ Book author:\" + author
                + \"\ Number of ratings: \" + numberOfRatings
                + \"\ Avg rating: \" + findAvgRating()
                + \"\ Price: \" + price
                + \"\ \" + bookRecommendation();
    }
}

Driver.java


import javax.swing.JOptionPane;
import static javax.swing.JOptionPane.showMessageDialog;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Sam
*/
public class Driver {
    public Book getInput() {
        Book b1;
        String title =JOptionPane.showInputDialog(\"Title\");
        String author =JOptionPane.showInputDialog(\"Author\");
        String choice =JOptionPane.showInputDialog(\"Do you want to add more info\");
        if (choice.startsWith(\"y\")){
            String price =JOptionPane.showInputDialog(\"Price\");
            String hasHardCover =JOptionPane.showInputDialog(\"Has hard cover?\");
            b = new Book(title, author, Float.parseFloat(price), hasHardCover.equalsIgnoreCase(\"yes\"));
        }
        else
            b1 = new Book(title, author);
        choice =JOptionPane.showInputDialog(\"Do you want to add rating info\");
      
        while (choice.startsWith(\"y\")){
            int rating =Integer.parseInt(JOptionPane.showInputDialog(\"add rating\"));
            if(rating>=1 && rating <= 4)
                b1.addRating(rating);
            else
                JOptionPane.showMessageDialog(null, \"Invalid rating\", \"Error\", JOptionPane.ERROR_MESSAGE);
            choice =JOptionPane.showInputDialog(\"Do you want to add rating info\");
        }
      
        return b1;
    }
  
    public static void main(String[] args) {
        Book b = new Driver().getInput();
        JOptionPane.showMessageDialog(null, b.toString(), \"details\", JOptionPane.INFORMATION_MESSAGE);
    }
}

Concepts Utilized in this Project UML diagrams Menu driven program Java fundamentals, including decision structures, loops Constructors, Overloaded constructors
Concepts Utilized in this Project UML diagrams Menu driven program Java fundamentals, including decision structures, loops Constructors, Overloaded constructors
Concepts Utilized in this Project UML diagrams Menu driven program Java fundamentals, including decision structures, loops Constructors, Overloaded constructors
Concepts Utilized in this Project UML diagrams Menu driven program Java fundamentals, including decision structures, loops Constructors, Overloaded constructors

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site