Пример #1
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");
    }
  }
Пример #2
0
  public BorrowUC_CTL(
      ICardReader reader,
      IScanner scanner,
      IPrinter printer,
      IDisplay display,
      IBookDAO bookDAO,
      ILoanDAO loanDAO,
      IMemberDAO memberDAO) {

    this.bookDAO = bookDAO;
    this.memberDAO = memberDAO;
    this.loanDAO = loanDAO;

    this.ui = new BorrowUC_UI(this);
    this.reader = reader;
    reader.addListener(this);
    this.scanner = scanner;
    scanner.addListener(this);
    this.printer = printer;
    this.display = display;

    state = EBorrowState.CREATED;
  }