Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class called Book that has the following attribures: copiesInStock yearO

ID: 3660741 • Letter: W

Question

Write a class called Book that has the following attribures: copiesInStock yearOfPublication, isbn, price, title, publisher, author. This class will later be used in a test method to compile a listing of 10 Book objects of the same listed above. Write proper gets and sets to affect the values. Set the year of publication by default to 1900. Allow the user the option to enter values for ISBN, price and copiesInStock. If the user chooses to generate these values use Math.random() to randomly generate values for the ISBN to be in a format 9999-9999-9999-9999 (an acceptabel isbn might also appear as 2465-123-4523), copiesInStock not to exceed 100, price of a book not to exceed $100, and a year of publication to be not less than the year 1900 but no greater than the current year (1900-2012). Write 10 records of your book array type object you created that properly show this formatting, then dump your file to Console or JOptionPane. Math.random() hints souble someValue = 100 * Math.random() //100 is the upperlimit and //returns a double by default. This is also known as a "seed". //Sometimes called "seeding" a random number int someOtherValue = (int) (100 * Math.Random());

Explanation / Answer

public class Book { private String title; private String publisher; private String author; private int copies; private int dpublication = 1900; private int book_num; private int price; Book(String in_title, String in_publisher, String in_author, int in_copies, int in_dpublication, int in_book_num, int in_price) { title = in_title; publisher=in_publisher; author=in_author; copies=in_copies; dpublication=in_dpublication; book_num=in_book_num; price=in_price; } public String get_title() { return title; } public String get_publisher() { return publisher; } public String get_author() { return author; } public void setCopies(int copies) { copies = 100; } public int get_copies() { return copies; } public void setYear(int dpublication) { dpublication = 1900; } public int getdpublication() { return dpublication; } public int get_book_num() { return book_num; } public void setPrice(double price) { price = 100; } public int get_price() { return price; } } PLUS import javax.swing.JOptionPane; public class BookInventory { public static void main(String[] args) { String display1 = "This program will ask you to enter the isbn numbers, price and number of copies in stock for ten Books then ask you whether or not you would like to view the records sorted or unsorted."; String display2 = "Thank you. Click OK to display the unsorted records."; String display3 = "Click OK to display the records sorted by stock number."; String display4 = "Click OK to display the records sorted by title."; String ques1= "Please enter the isbn number of the Book."; String ques2= "Please enter the price of the Book."; String ques3= "Please enter the number of copies in stock."; String ques4= "Please enter the year of publication."; String ques5= "Please enter the title of the book."; String ques6= "Please enter the author of the book."; String bookName; String title= ""; String publisher= ""; String author= ""; int counter = 0; int rand_num; int rand_year; int copies; double rand_price; Book[] someBooks = new Book[10]; JOptionPane.showMessageDialog(null, display1, "Program Notification", JOptionPane.INFORMATION_MESSAGE); for(counter=0; counter
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote