for(int i = 0; i < bookList.size(); i++) { Book b = bookList.get(0); title = b.getTitle(i); s += title; }
public Book searchTitle(String title) { for (Book book : library) { if (book.getTitle().equals(title)) { return book; } } return null; }
Request request = requestor.request(Void.class, Book.class) .path("server").segment("books").segment(1) .get(new AsyncCallback<Book>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(Book result) { Window.alert("My book title: " + result.getTitle()); } });
public class Book implements Comparable<Book> { public int compareTo(Book otherBook) { return title.compareTo(otherBook.getTitle()); } }
public class MyBook { private Book book; public MyBook(...) { book = new Book(...); } public String getTitle() { return book.getTitle(); } ...etc }
ArrayList<String> matches = new ArrayList<String>(); Pattern p = Pattern.compile(regex); for (Book book:list) { if (p.matcher(book.getTitle()).matches()) { matches.add(book); } }
public Book getBook(String title, String author){ Book book =null; for (int i = 0; i < listOfBooks.size(); i++){ book = listOfBooks.get(i); if (book.getTitle().equals(title) && book.getAuthor().equals(author){ return book; } } return book; }
Book tempBook; for (int x=0;x<bkList.Size();x++){ tempBook=bkList.get(x); System.out.println(tempBook.getTitle()+" "+tempBook.getLevel()); }
for (Book book : books) { if (book.getTitle().equals(title)) { book.borrowed(); } }
Query query = em.createQuery( "Select b FROM Book b JOIN b.student s " + "WHERE s.name = :studentname AND b.followUpNumber = :follownbr" ); query.setParameter("studentname", "Student name 6"); query.setParameter("follownbr", Long.valueOf(4)); Book book = (Book)query.getSingleResult(); System.out.println("Found book = " + book.getTitle()); System.out.println("book follow nbr= " + book.getFollowUpNumber());
double totalPrice = 0.0; for (int i = 0; i < bookArray.length; i++) { //can't use foreach because of use of parallel arrays bookArray & quantityArray Book b = bookArray[i]; double price = b.getPrice() * quantityArray[i]; totalPrice += price; String bookStr = String.format(" %s, %s %s", b.getTitle(), b.getIsbn(), DecimalFormat.getCurrencyInstance().format(price)); JOptionPane.showMessageDialog(null, bookStr); } String totalStr = String.format("Total Charge: %s", DecimalFormat.getCurrencyInstance().format(totalPrice))); JOptionPane.showMessageDialog(null, totalStr);
@Override public int compareTo(Book o){ if (this.getNumberOfPages() != o.getNumberOfPages()) return new Integer(this.getNumberOfPages()).compareTo(o.getNumberOfPages()); if (this.getPrice() != o.getPrice()) return new Double(this.getPrice()).compareTo(o.getPrice()); if(!this.getTitle().equalsIgnoreCase(o.getTitle())) return this.getTitle().compareToIgnoreCase(o.getTitle()); return 0; }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Book b = bookList.get(position); Intent i = new Intent(Romance.this, ViewBook.class) .putExtra("bookname", b.getTitle()) .putExtra("category", b.getCategory()) .putExtra("Bauthor", b.getAuthor()) .putExtra("Bedition", b.getEdition); startActivity(i); }
public class BookTest { public static void main(String[] args) { Author fullAuth = new Author("Bob", "Marly", "Russian"); Book bookInf = new Book("Alice", fullAuth, 60000, 2000); //Student studInf = new Student("Ted", "21/10/1992", "Male", "Simmonds Close 63", "King Close 65", "Computing", 12000); System.out.println(fullAuth.getAuNational() + " " + fullAuth.getAuFname()); System.out.println(bookInf.getTitle() + " " + bookInf.getPrice()); //System.out.println(studInf.getName() + " " + studInf.getName()); } }
public int compareTo(Book b) { int compare = title.compareTo(b.getTitle()); // the following lines only change the compare value if it is still 0 compare = (compare != 0) ? compare : author.compareTo(b.getAuthor()); compare = (compare != 0) ? compare : Double.compare(price, b.getPrice()); return (compare != 0) ? compare : publisher.compareTo(b.getPubisher()); }
public void showDataInTable(ArrayList<Book> listOfBooks, JTable table){ DefaultTableModel model = new DefaultTableModel(new Object[]{"Title", "Author"}, 0); for(Book book:listOfBooks){ model.addRow(new Object[]{book.getTitle(), book.getAuthor()}); } table.setModel(model); }