private void setupTestData() {
    IBook[] book = new IBook[15];
    IMember[] member = new IMember[6];

    book[0] = bookDao_.addBook("author1", "title1", "callNo1");
    book[1] = bookDao_.addBook("author1", "title2", "callNo2");
    book[2] = bookDao_.addBook("author1", "title3", "callNo3");
    book[3] = bookDao_.addBook("author1", "title4", "callNo4");
    book[4] = bookDao_.addBook("author2", "title5", "callNo5");
    book[5] = bookDao_.addBook("author2", "title6", "callNo6");
    book[6] = bookDao_.addBook("author2", "title7", "callNo7");
    book[7] = bookDao_.addBook("author2", "title8", "callNo8");
    book[8] = bookDao_.addBook("author3", "title9", "callNo9");
    book[9] = bookDao_.addBook("author3", "title10", "callNo10");
    book[10] = bookDao_.addBook("author4", "title11", "callNo11");
    book[11] = bookDao_.addBook("author4", "title12", "callNo12");
    book[12] = bookDao_.addBook("author5", "title13", "callNo13");
    book[13] = bookDao_.addBook("author5", "title14", "callNo14");
    book[14] = bookDao_.addBook("author5", "title15", "callNo15");

    member[0] = memberDao_.addMember("fName0", "lName0", "0001", "email0");
    member[1] = memberDao_.addMember("fName1", "lName1", "0002", "email1");
    member[2] = memberDao_.addMember("fName2", "lName2", "0003", "email2");
    member[3] = memberDao_.addMember("fName3", "lName3", "0004", "email3");
    member[4] = memberDao_.addMember("fName4", "lName4", "0005", "email4");
    member[5] = memberDao_.addMember("fName5", "lName5", "0006", "email5");

    Calendar cal = Calendar.getInstance();
    Date now = cal.getTime();

    // create a member with overdue loans
    for (int i = 0; i < 2; i++) {
      ILoan loan = loanDao_.createLoan(member[1], book[i]);
      loanDao_.commitLoan(loan);
    }
    cal.setTime(now);
    cal.add(Calendar.DATE, ILoan.LOAN_PERIOD + 1);
    Date checkDate = cal.getTime();
    loanDao_.updateOverDueStatus(checkDate);

    // create a member with maxed out unpaid fines
    member[2].addFine(10.0f);

    // create a member with maxed out loans
    for (int i = 2; i < 7; i++) {
      ILoan loan = loanDao_.createLoan(member[3], book[i]);
      loanDao_.commitLoan(loan);
    }

    // a member with a fine, but not over the limit
    member[4].addFine(5.0f);

    // a member with a couple of loans but not over the limit
    for (int i = 7; i < 9; i++) {
      ILoan loan = loanDao_.createLoan(member[5], book[i]);
      loanDao_.commitLoan(loan);
    }
    // Note - there are 9 total loans.
  }
Ejemplo n.º 2
0
  private void setState(EBorrowState state) {
    System.out.println("Setting state: " + state);

    this.state = state;
    ui.setState(state);

    switch (state) {
      case INITIALIZED:
        reader.setEnabled(true);
        scanner.setEnabled(false);
        break;

      case SCANNING_BOOKS:
        reader.setEnabled(false);
        scanner.setEnabled(true);
        this.bookList = new ArrayList<IBook>();
        this.loanList = new ArrayList<ILoan>();
        scanCount = borrower.getLoans().size();

        // clear currentBook display
        ui.displayScannedBookDetails("");
        // clear pending loan display
        ui.displayPendingLoan("");
        break;

      case CONFIRMING_LOANS:
        reader.setEnabled(false);
        scanner.setEnabled(false);
        // display pending loans
        ui.displayConfirmingLoan(buildLoanListDisplay(loanList));
        break;

      case COMPLETED:
        reader.setEnabled(false);
        scanner.setEnabled(false);
        for (ILoan loan : loanList) {
          loanDAO.commitLoan(loan);
        }
        printer.print(buildLoanListDisplay(loanList));
        close();
        break;

      case CANCELLED:
        reader.setEnabled(false);
        scanner.setEnabled(false);
        close();
        break;

      case BORROWING_RESTRICTED:
        reader.setEnabled(false);
        scanner.setEnabled(false);
        ui.displayErrorMessage(
            String.format("Member %d cannot borrow at this time.", borrower.getID()));
        System.out.format("Member %d cannot borrow at this time.", borrower.getID());
        break;

      default:
        throw new RuntimeException("Unknown state");
    }
  }