public LibraryBook getBookfromBorrowed(String bookID) { LibraryBook book = null; ArrayList<LibraryBook> booklist = getBorrowedBooks(); for (LibraryBook b : booklist) { if (bookID.equals(b.getBookNumber())) { book = b; } } return book; }
/* Prints member object as following format: * ID: id * Name: name * Phone Number: phone number * @see model.LibraryMember#print() */ @Override public void print() { String member = String.format("%s: %s\n%s: %s\n%s: %s", ID, id, NAME, name, PHONENUMBER, phoneNumber); String books = ""; System.out.printf("%s\n", member); // Printing out booklist System.out.printf("%s: ", ITEMS); for (LibraryBook book : booklist) { books += (book.getBookNumber() + " "); } System.out.printf("%s\n", books); }
public static void main(String[] args) { LibraryCollection HarryPotterSeries = new LibraryCollection(); LibraryBook HarryPotter1 = new LibraryBook(); HarryPotter1.BookTitle = "Harry Potter and the Sorcerer's Stone"; LibraryBook HarryPotter2 = new LibraryBook(); HarryPotter2.BookTitle = "Harry Potter and the Chamber of Secrets"; HarryPotterSeries.arrayOfBookCollection.add(HarryPotter1); HarryPotterSeries.arrayOfBookCollection.add(HarryPotter2); HarryPotterSeries.displayCollection(); LibraryBook foundTestBook = HarryPotterSeries.findBookInCollection("Harry Potter and the Sorcerer's Stone"); LibraryBook foundTestBook2 = HarryPotterSeries.findBookInCollection(HarryPotter2.BookTitle); LibraryMenu.displayMessage(foundTestBook.BookTitle); LibraryMenu.displayMessage(foundTestBook2.BookTitle); }
/** save To save members' information into a binary file */ public void save() { ObjectOutputStream oout = null; Member tm; ArrayList<String> booksBorrowed = new ArrayList<String>(); try { oout = new ObjectOutputStream(new FileOutputStream("members1.dat")); // Loop through memberMap and process each entry // Structure for writing // __________________________________________________________ // |String|String|String|Boolean or Double|ArrayList<String>| // ---------------------------------------------------------- for (Map.Entry<String, Member> entry : memberMap.entrySet()) { tm = entry.getValue(); oout.writeUTF(tm.getMemberID()); oout.writeUTF(tm.getName()); oout.writeUTF(tm.getPhoneNumber()); if (tm instanceof Staff) { oout.writeBoolean(((Staff) tm).isBookOverdue()); } else { oout.writeDouble(((Student) tm).getFinesOwing()); } for (LibraryBook b : tm.getBooklist()) { booksBorrowed.add(b.getBookNumber()); } oout.writeObject(booksBorrowed); } } catch (Exception e) { Log.e(e.getMessage()); } finally { try { oout.close(); } catch (IOException e) { Log.e(e.getMessage()); } } }