# (DD08) Business Logic — ConsoleUI.listLoans() [5 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `ui.ConsoleUI` |
| Layer | Controller |
| Module | `ui` (Package: `ui`) |

## 1. Role

### ConsoleUI.listLoans()

This method is a console-screen action that retrieves the current set of active loan records and displays them to the user. In business terms, it supports the “loan inquiry/listing” use case: a user chooses the loan-list option from the UI menu, the application asks the service layer for the active-loan collection, and the screen either prints the records or shows an empty-state message when no loans exist. The method does not transform, filter, or persist loan data; instead, it acts as a thin presentation-layer router that delegates retrieval to `loanService` and then renders the result. Its design pattern is simple request delegation plus conditional presentation logic, which keeps the console workflow readable and isolates business retrieval in the service layer. In the larger system, this method is the screen-level entry point for the loan list operation and is typically invoked from the main menu selection branch.

## 2. Processing Pattern (Detailed Business Logic)

```mermaid
flowchart TD
START(["listLoans()"])
GET_LOANS["loanService.getActiveLoans()"]
CHECK_EMPTY{"loans.isEmpty()?"}
NO_LOANS["Print \"No active loans.\" and return"]
PRINT_ALL["loans.forEach(System.out::println)"]
END_NODE(["Return"])
START --> GET_LOANS
GET_LOANS --> CHECK_EMPTY
CHECK_EMPTY -- "Yes" --> NO_LOANS
CHECK_EMPTY -- "No" --> PRINT_ALL
NO_LOANS --> END_NODE
PRINT_ALL --> END_NODE
```

The method performs a single service call to obtain all active loans, then branches on whether the returned collection is empty. If the collection has no entries, the UI emits a business-friendly empty-state message and terminates. If records are present, the UI iterates over the collection and prints each loan object to the console using its string representation.

## 3. Parameter Analysis

| No | Parameter Name | Type | Business Description |
|----|---------------|------|---------------------|
| - | (none) | - | This method takes no input parameters. It operates entirely from screen state and the injected `loanService` dependency. |

Instance fields or external state read by the method:
- `loanService` - service dependency used to retrieve the active loan list.
- Console output stream via `System.out` - used to present the empty-state message and each loan record.

## 4. CRUD Operations / Called Services

| CRUD | SC / CBS | SC Code | Entity / DB | Operation Description |
|------|----------|---------|-------------|----------------------|
| R | `getActiveLoans` | N/A | Loan collection / active loan domain model | Reads the set of active loan records for display on the console. |

Notes:
- The method contains one service read call and no create, update, or delete operations.
- No SC/CBS-specific code identifier is visible in the source for `loanService.getActiveLoans()`.

## 5. Dependency Trace

### Pre-computed evidence from code analysis graph:

No screen/batch entry points found within 8 hops. Direct callers found: 2 methods.
Terminal operations from this method: -

| # | Caller (Screen/Batch) | Call Chain (Full Path to this Method) | Terminal (SC / CRUD / Entity) |
|---|----------------------|--------------------------------------|-------------------------------|
| 1 | Screen: `ConsoleUI` menu branch | `ConsoleUI` menu selection `case 8 -> listLoans()` -> `ConsoleUI.listLoans()` | `getActiveLoans [R] Loan collection` |

The available search results show that `listLoans()` is invoked from the console menu selection branch in the same class. No additional upstream screen or batch entry points were identified in the provided code sample, so the dependency trace is limited to the direct UI dispatch path.

## 6. Per-Branch Detail Blocks

**Block 1** — **CALL** `(entry from menu selection)` (L96)

> This block represents the screen action that starts the loan-list flow.

| # | Type | Code |
|---|------|------|
| 1 | CALL | `loanService.getActiveLoans();` |

**Block 2** — **IF** `(loans.isEmpty())` (L97)

> This block determines whether the loan list has any active records to display.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `loans.isEmpty();` |

**Block 2.1** — **ELSE** `(loans is not empty)` (L98)

> When data exists, the method renders each active loan to the console.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `loans.forEach(System.out::println);` |

**Block 2.2** — **IF branch result** `(loans is empty)` (L97)

> When no loans are available, the UI displays a simple empty-state message and exits.

| # | Type | Code |
|---|------|------|
| 1 | EXEC | `System.out.println("No active loans.");` |
| 2 | RETURN | `return;` |

**Block 3** — **RETURN** `(method end)` (L99-L100)

> The method terminates after either printing all loans or printing the empty-state message.

| # | Type | Code |
|---|------|------|
| 1 | RETURN | `void` completion |

## 7. Glossary

| Term | Type | Business Meaning |
|------|------|------------------|
| `loanService` | Field / Dependency | Service layer component that supplies loan-domain data to the UI. |
| `getActiveLoans` | Method | Retrieves the current list of active loan records for display. |
| `Loan` | Entity / Domain object | A loan record shown in the console, typically representing an active borrowing arrangement. |
| active loan | Business term | A loan that is currently open and not yet completed, canceled, or closed. |
| console UI | Business term | Text-based user interface that displays business data and accepts menu-driven commands. |
| `System.out.println` | Technical operation | Standard console output used to present messages to the user. |
| empty-state message | Business term | User-facing message shown when no active loan records are available. |
| menu selection | UI flow term | The user’s choice from the main console menu that routes execution to this method. |