Question: How do I write this with java doc? Book.java public class Book { private String title; private String author; private int numberOfRatings; private int totalRating;

How do I write this with java doc?

Book.java

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); } }

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!