Question: public class Book { // instance variables private String isbn; private String title; private String author; private double cost; /** * Default constructor for objects

public class Book { // instance variables private String isbn; private String title; private String author; private double cost;

/** * Default constructor for objects of class Book. */ public Book() { // initialize instance variables isbn = title = author = ""; cost = 0; } /** * Overloaded constructor for objects of class Book. * * @param id Book's ISBN * @param description Book's title * @param name Book's author * @param value Book's cost */ public Book(String id, String description, String name, double value) { // initialize instance variables isbn = id; title = description; author = name; cost = value; } /** * Copy constructor for objects of class Book. * * @param b another Book object */ public Book(Book b) { // initialize instance variables this.isbn = b.isbn; this.title = b.title; this.author = b.author; this.cost = b.cost; } /** * Updates the Book's ISBN. * * @param id Book's ISBN */ public void setISBN(String id) { isbn = id; } /** * Updates the Book's author. * * @param name Book's author */ public void setAuthor(String name) { author = name; } /** * Updates the Book's title. * * @param description Book's title */ public void setTitle(String description) { title = description; } /** * Updates the Book's cost. * * @param value Book's cost */ public void setCost(double value) { cost = value; } /** * Determines if a Book is the same as another Book based on the ISBN. * * @param b another Book object * @return whether this Book is equal to the other Book */ public boolean equals(Book b) { return this.isbn.equals(b.isbn); } /** * Compares a Book based on their cost. * * @param s another Book object * @return whether this Book's cost is greater than, less than, or equal to the other Book's cost */ public int compareTo(Book b) { if(this.cost - b.cost > 0) return 1; else if(this.cost - b.cost < 0) return -1; else return 0; } /** * Creates a string that represents a Book. * * @return the string that represents a Book */ public String toString() { return "ISBN: " + isbn + " Title: " + title + " Author: " + author + " Cost: $" + cost; } }

1. Download the books.csv file from Canvas. Open this file with notepad to see the format, dont worry if this file defaulted to open in excel.

2. Download the Book.java file from Canvas. Import this file into your java project.

3. Create a class called BookStoreManagementDriver. This class should contain the methods listed below.

a. main method, which should do the tasks listed below.

i. Create an array of object references of type Book. You may default the size to 5.

ii. Ask the user for keyboard input for the input file name and output file name. Then create the Scanner object for the input file and the PrintWriter object for the output file.

iii. Then ask the user for keyboard input whether to sort the by high to low, or low to high cost.

iv. Read the file from step 1 in line by line. For each line split it using the StringTokenizer. Then use each set of tokens to create a Book object in the array of Books.

Note: Each book should have a unique location inside the array.

v. Use the compareTo method to sort the books based on the users choice (described above). (Hint: use logic similar to selection sort)

vi. Use the equals method to record which books are duplicates. (Hint: use a boolean array to help determine which are duplicates)

vii. Print the ordered and refined book store data into the output file.

viii. Print to the terminal window after each task has been completed. So that the user can see what has been completed.

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!