Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions

Question

Understand why empowerment is so important in many frontline jobs.

Answered: 1 week ago

Question

Explain walter's model of dividend policy.

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago