Question: Code in Java, please Use the data from the files attached to generate book objects. Each book object should contain a book title, an ISBN
Code in Java, please
Use the data from the files attached to generate book objects. Each book object should contain a book title, an ISBN number, an author name formed by a randomly selected first name a randomly selected last name, and a randomly generated price ranging from $0.00 to $99.99. Store these thousands of book objects in an array called books. Use the Java API Arrays.sort() method to sort the books array. Sort the array by book titles and authors last names, respectively. Compare the time it took between the two operations
Here is the book class I have
public class Book {
private String title;
private String isbn;
private String firstName;
private String lastName;
private double price;
public Book(String title, String isbn, String firstname, String lastname, double price) {
super();
this.title = title;
this.isbn = isbn;
this.firstName = firstname;
this.lastName = lastname;
this.price = price;
}
@Override
public String toString() {
return "Title: " + title + ", ISBN: " + isbn + ", Author: " + firstName + " " + lastName + ", Price: $" + price;
}
public int compareTo(Book o) {
return Double.compare(this.price, o.price);
}
public String getTitle() {
return title;
}
public String getLastName() {
return lastName;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
