// Exercise 2: bounded type parameters (medium)
//
// Implement:
//   - static <T extends Comparable<T>> T min(List<T> list): returns the
//     smallest element, using compareTo — only possible because T is
//     bounded by Comparable<T>.
//   - static <T extends Number & Comparable<T>> T clamp(T value, T lo, T hi):
//     returns value clamped into [lo, hi]. Needs BOTH bounds: Comparable
//     for compareTo, Number is unused directly here but demonstrates the
//     multi-bound `&` syntax (kept so callers are restricted to numeric
//     Comparable types, not arbitrary Comparable ones like String).

import java.util.List;

public class java_generics_exercise_2 {

    static <T extends Comparable<T>> T min(List<T> list) {
        // TODO: implement — iterate, keep the smallest via compareTo
        return null;
    }

    static <T extends Number & Comparable<T>> T clamp(T value, T lo, T hi) {
        // TODO: implement — if value < lo return lo; if value > hi return hi; else value
        return null;
    }

    // --- self-check: do not modify below this line ---
    public static void main(String[] args) {
        boolean ok = true;

        ok &= min(List.of(3, 1, 4, 1, 5, 9, 2, 6)) == 1;
        ok &= min(List.of("pear", "apple", "banana")).equals("apple");

        ok &= clamp(5, 0, 10) == 5;
        ok &= clamp(-3, 0, 10) == 0;
        ok &= clamp(15, 0, 10) == 10;
        ok &= clamp(2.5, 0.0, 1.0) == 1.0;

        System.out.println(ok ? "PASS" : "FAIL");
    }
}
