조건분기

2026년 6월 16일 09:30분

신명기 11장에서 순종하면 비를 내리고 불순종하면 비를 막겠다는 분기 조건이 선언됩니다. 조건에 따라 전혀 다른 결과가 실행됩니다. 나는 순종 여부를 입력받아 두 경로를 분기 실행하는 조건기를 만들었습니다.

package com.jesusbornd.deuteronomy;

public class Deuteronomy_11_Chapter_Lv2 {
    sealed interface Outcome permits Blessing, Curse {}
    record Blessing(String detail) implements Outcome {}
    record Curse(String detail)   implements Outcome {}

    static Outcome evaluate(boolean obedient) {
        return obedient
            ? new Blessing("이른 비와 늦은 비 공급 — 풍년")
            : new Curse("하늘 닫힘 — 가뭄, 땅이 소출 없음");
    }

    public static void main(String[] args) {
        for (boolean ob : new boolean[]{true, false}) {
            Outcome o = evaluate(ob);
            String label = ob ? "순종" : "불순종";
            switch (o) {
                case Blessing b -> System.out.printf("[%s] ✅ %s%n", label, b.detail());
                case Curse    c -> System.out.printf("[%s] ❌ %s%n", label, c.detail());
            }
        }
    }
}

def evaluate(obedient: bool) -> tuple[str, str]:
    if obedient:
        return "✅", "이른 비와 늦은 비 공급 — 풍년"
    return "❌", "하늘 닫힘 — 가뭄, 땅이 소출 없음"

if __name__ == "__main__":
    for ob in [True, False]:
        label = "순종" if ob else "불순종"
        icon, detail = evaluate(ob)
        print(f"[{label}] {icon} {detail}")

Comments

Avatar
 2026년 6월 16일 11:34분

결과가 완전히 갈리는 조건 분기, 설계 전에 경우의 수를 세어야 하는군요.



Search

← 목록으로