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; }
public List<Book> searchBook(String Author2){ List<Book> kopia = new ArrayList <Book>(); for(Book book : reg){ if(book.getAuthor().equalsIgnoreCase(Author2) || book.getTitle().toLowerCase().indexOf(Author2.toLowerCase()) != -1){ kopia.add(book); } } return kopia; }
Book book=itr.next(); if(book.getAuthor().equals(author)&&(book.getTitle().equals(title))){
TextView title = (TextView) listItemView.findViewById(R.id.title_text_view); TextView author = (TextView) listItemView.findViewById(R.id.author_text_view); @Override public View getView(int position, View convertView, ViewGroup parent) { // Check if the existing view is being reused, otherwise inflate the view View listItemView = convertView; if (listItemView == null) { listItemView = LayoutInflater.from(getContext()).inflate( R.layout.list_item_view, parent, false); } Book currentBook = getItem(position); TextView title = (TextView) listItemView.findViewById(R.id.title_text_view); title.setText(currentBook.getTitle()); TextView author = (TextView) listItemView.findViewById(R.id.author_text_view); author.setText(currentBook.getAuthor()); return listItemView; }
import java.util.Comparator; public class Book { String author; String title; int id; public boolean equals(Object o) { return id == ((Book) o).id; } //getters and setters //other methods } class BookComparator implements Comparator<Book>{ @Override public int compare(Book o1, Book o2) { if(o1.getAuthor() == o2.getAuthor() && o1.getTitle() == o2.getTitle()) return 0; return 1; } }
public String checkForBookUsingInfo(){ int index = 0; Book bookObject = null; String returnValue = "Book not found"; String title = ""; String author = ""; Boolean isFound = false; System.out.println("Please enter the name of a book to search for."); String anyTitle = keybd.nextLine(); System.out.println("Please enter the name of an author to search for."); String anyAuthor = keybd.nextLine(); while (index <bookList.size() && isFound == false ){ bookObject = bookList.get(index); title = bookObject.getTitle(); author = bookObject.getAuthor(); if ((title.equals(anyTitle)) && (author.equals(anyAuthor))){ returnValue = "Book is in library."; } index++; } return returnValue; }
@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); }
Book bookA = new Book("George Orwell","Animal Farm") System.out.print("Book: " + bookA.getTitle() + " by " + bookA.getAuthor());
public String getAuthorFullName(String title) { for (Book authorName : inventory) { if (authorName.getTitle() != null && authorName.getTitle().equals(title)) { return authorName.getAuthor().getName().getFullName(); } } return null; }
public String getAuthorFullName(String title){ for (Book authorName : inventory) if (authorName.getTitle() != null && authorName.getTitle().equals(title)) return authorName.getAuthor().getName().getFullName(); return null; }
public String getAuthorFullName(String title) { for (Book authorName : inventory) { if (authorName.getTitle() != null && authorName.getTitle().equals(title)) { return authorName.getAuthor().getName().getFullName(); } } return null; }
ArrayList<Book> bookInfo = getInfo(); for (Book book: bookInfo) { if (book.equals(book.getTitle()) { authorTextField.setText( book.getAuthor()); // ... for the rest of the text fields return; } }
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); }
public int compareTo(Book book){ if(book == null){ throw new NullPointerException("Book passed is null!"); } if(this.getAuthor().equals(book.getAuthor())){ /*Most significant field*/ if(this.getTitle().equals(book.getTitle())){ /*Next Most significant field*/ if(this.getPrice().equals(book.getPrice()){ return (this.getPublisher().compareTo(book.getPublisher()); } else{ return (int)(this.getPrice()-book.getPrice()); } } else{ return this.getTitle().compareTo(book.getTitle()); }} else{ return this.getAuthor().compareTo(book.getAuthor()); } }
public int compareTo(Book book) { if (book == null) { throw new NullPointerException("Book passed is null!"); } if (!this.getAuthor().equals(book.getAuthor())) { return this.getAuthor().compareTo(book.getAuthor()); } if (! this.getTitle().equals(book.getTitle())) { return this.getTitle().compareTo(book.getTitle()); } if (this.getPrice() != book.getPrice()) { return (int) (this.getPrice() - book.getPrice()); } return publisher.compareTo(book.getPublisher()); }
System.out.println(bb.getAuthor()); System.out.println(bb.getTitle()); System.out.println(bb.getDescription());
public void index(Book item) throws IOException{ if (iw == null) { iw = new IndexWriter(FSDirectory.open(new File(directory)), new IndexWriterConfig(Version.LATEST, new EnglishAnalyzer())); } iw.deleteDocuments(new Term(Book.ID, String.valueOf(item.getISBN()))); Document doc = new Document(); doc.add(new LongField(Book.ID, item.getISBN(),Field.Store.YES)); doc.add(new StringField(Book.AUTHOR, item.getAuthor(),Field.Store.YES)); doc.add(new StringField(Book.TITLE, item.getTitle(),Field.Store.YES)); doc.add(new TextField(Book.CONTENT, item.getContent(),Field.Store.YES)); iw.addDocument(doc); iw.commit(); }
public int compareTo(Book book){ if(book == null){ throw new NullPointerException("Book passed is null!"); } if(this.getAuthor().equals(book.getAuthor())){ /*Most significant field*/ if(this.getTitle().equals(book.getTitle())) /*Next Most significant field*/ if(this.getPublisher().equals(book.getPublisher())){ //assuming that you have a getPublisher() method return (int)(this.getPublisher().compareTo(book.getPublisher())); } else { return (int)(this.getPrice()-book.getPrice()); } else return this.getTitle().compareTo(book.getTitle()); } else return this.getAuthor().compareTo(book.getAuthor()); } }
public void displayBookWithBiggestPercentageMarkup(){ Collection<Book> books = getCollectionOfItems(); if (books.size() == 0) { return; } Iterator<Book> it = books.iterator(); double highestPercent = 0; Book highestPercentBook = null; while(it.hasNext()){ Book b = it.next(); double percent = b.getSuggestedRetailPriceDollars() / b.getManufacturingPriceDollars() * 100.0; if (percent > highestPercent) { highestPercent = percent; highestPercentBook = b; } } System.out.println("Highest markup is " + highestPercent + " " + highestPercentBook.getTitle() + " " + highestPercentBook.getAuthor().getName().getLastName()); }