Ejemplo n.º 1
0
  private static void initLibrary(Library library)
      throws ParserConfigurationException, SAXException, IOException,
          IllegalLoanOperationException {

    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

    loadCustomersFromXml(library, builder, new File("data/customers.xml"));

    loadBooksFromXml(library, builder, new File("data/books.xml"));

    // create pseudo random books and loans
    createBooksAndLoans(library);

    Collections.sort(library.getCustomers());

    System.out.println("Initialisation of the library was successful!\n");
    System.out.println("Books in library: " + library.getBooks().size());
    System.out.println("Customers: " + library.getCustomers().size() + "\n");
    System.out.println("Copies in library: " + library.getCopies().size());
    System.out.println("Copies currently on loan: " + library.getLentOutBooks().size());
    int lentBooksPercentage =
        (int) (((double) library.getLentOutBooks().size()) / library.getCopies().size() * 100);
    System.out.println("Percent copies on loan: " + lentBooksPercentage + "%");
    System.out.println("Copies currently overdue: " + library.getOverdueLoans().size());
  }
Ejemplo n.º 2
0
 private static Customer getCustomer(Library library, int position) {
   return library.getCustomers().get(position % library.getCustomers().size());
 }