Question: Using these three classes.... public class Book { private String title; private String author; private double price; public Book() { } public Book(String myTitle, String

Using these three classes....

public class Book { private String title; private String author; private double price; public Book() { } public Book(String myTitle, String myAuthor, double myprice) { title = myTitle; author = myAuthor; price = myprice; } public String toString() { return getTitle() + " written by " + getAuthor() + ", price is " + this.price; } public double getPrice() { return price; } public void serPrice(double myPrice) { price = myPrice; }

public String getTitle() { return title; }

public void setTitle(String title) { this.title = title; } public String getAuthor() { return author; }

public void setAuthor(String author) { this.author = author; } } _____________________________________________________________

public class BookStore { private ArrayList booklist; public BookStore() { booklist = new ArrayList<>(); } public void printoutBookList() { System.out.println("===== My book store has ========"); for (Book abook : booklist) { System.out.println(abook); } System.out.println("================================="); } public void printoutBookList(ArrayList mylist) { System.out.println("===== My book list has ========"); for (Book abook : mylist) { System.out.println(abook); } System.out.println("================================="); } public ArrayList searchForTitle( String searchString ) { ArrayList searchResult = new ArrayList<>(); Book aBook; for (int i =0; i

public ArrayList getBooklist() { return booklist; }

public void setBooklist(ArrayList booklist) { this.booklist = booklist; } } _______________________________________________________________

public class BookStoreManager {

public static void main(String[] args) { BookStore mystore = new BookStore(); // initialize booklist mystore.getBooklist().add( new Book( "Intro to Java", "James", 56.99 ) ); mystore.getBooklist().add( new Book( "Advanced Java", "Green", 65.99 ) ); mystore.getBooklist().add( new Book( "Java Servlets", "Brown", 75.99 ) ); mystore.getBooklist().add( new Book( "Intro to HTML", "James", 29.49 ) ); mystore.getBooklist().add( new Book( "Intro to Flash", "James", 34.99 ) ); mystore.getBooklist().add( new Book( "Advanced HTML", "Green", 56.99 ) ); mystore.getBooklist().trimToSize( ); // printout the booklist mystore.printoutBookList(); // search for the books with title ... ArrayList javaBooks = mystore.searchForTitle("Java"); mystore.printoutBookList(javaBooks); } }

....add these two methods:

  1. Find the most expensive book (if there are 2 books have the same price, return one of them)

public Book getMostExpensiveBook ( )

  1. Find the books by a price range (include low and high)

public ArrayList getBooksForPriceRange(double low, double high

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!