i just want to make sure I did this correctly. Does it look right?
/** a method returning an ArrayList of Books whose price is less than a given number * @param searchDouble * @return */ public ArrayList<Book> searchForPrice(double searchDouble) { ArrayList<Book> searchResult = new ArrayList<>(); for(Book lessBook : library) { if((lessBook.getTitle()).indexOf((int) searchDouble)!=-1) searchResult.add(lessBook); } searchResult.trimToSize(); return searchResult; } }
The rest of my code for the array List:
public class BookStore { private ArrayList<Book> library; /**default constructor * instantiates ArrayList of Books */ public BookStore() { library=new ArrayList<>(); library.add(new Book("Intro to Java", "James", 56.99)); library.add(new Book("Advanced Java", "Green", 65.99)); library.add(new Book("Java Servlets", "Brown", 75.99)); library.add(new Book("Intro to HTML", "James", 29.49)); library.add(new Book("Intro to Flash", "James", 34.99)); library.add(new Book("Advanced HTML", "Green", 56.99)); library.trimToSize(); } /** toString * @return each book in library, one per line */ @Override public String toString() { String result = ""; for(Book tempBook : library) { result += tempBook.toString()+"\n"; } return result; }