// MovieCreditsDemoDriver.java
// Concept: Iterate over a collection and process each element — one language at a time.
//
// You've already done this in Python. The idea is identical here.
// What changes is the syntax — the rules Java uses to express the same logic.
//
// PYTHON VERSION (for comparison):
//   import time
//   credits = ["THE LAST SIGNAL", "Directed by", "  Ava Chen"]
//   for credit in credits:
//       print(credit)
//       time.sleep(1.2)
//
// JAVA VERSION: see below. Every extra word is there for a reason.
// ─────────────────────────────────────────────────────────────────────────────
// Java's philosophy: EXPLICITNESS and SAFETY.
// The compiler reads your code before it runs. If you tell it exactly what
// type each variable holds, it can catch mistakes at compile time — before
// they reach the user. Python trusts you to be right at runtime. Java checks.
// ─────────────────────────────────────────────────────────────────────────────

public class MovieCreditsDemoDriver {

    // Every Java program starts here. main() is the entry point.
    // "String[] args" lets the OS pass command-line arguments — ignore for now.
    public static void main(String[] args) {

        // ── DECLARING A STRING ARRAY ─────────────────────────────────────────
        // Python:  credits = ["THE LAST SIGNAL", "Directed by", ...]
        // Java:    String[] credits = {"THE LAST SIGNAL", "Directed by", ...};
        //          ^^^^^^^^  ← type required. String[] = "an array of text values."
        //                    Java won't let you skip this — it's a feature, not a flaw.
        //
        // Blank strings ("") create empty lines — a simple way to pace the scroll.

        String[] credits = {
            "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~",
            "   T H E   L A S T   S I G N A L",
            "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~",
            "",
            "Directed by",
            "    Ava Chen",
            "",
            "Produced by",
            "    Marcus Webb",
            "    Priya Nair",
            "",
            "Original Score",
            "    Theo Lindqvist",
            "",
            "Director of Photography",
            "    Samira Okonkwo",
            "",
            "Screenplay by",
            "    Jordan Reyes",
            "",
            "Visual Effects Supervisor",
            "    Yuki Tanaka",
            "",
            "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~",
            "     Thank you for watching.",
            "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~"
        };

        // ── THE FOR LOOP ──────────────────────────────────────────────────────
        // Python:  for credit in credits:          ← Java calls this "for-each"
        // Java:    for (int i = 0; i < credits.length; i++)
        //
        // Three parts inside the parentheses:
        //   int i = 0           — start: create a counter, begin at index 0
        //   i < credits.length  — stop:  keep going while i is less than array size
        //   i++                 — step:  after each loop, add 1 to i
        //
        // credits.length is Java's equivalent of Python's len(credits).
        // credits[i] retrieves the element at index i — same zero-based indexing as Python.

        System.out.println(); // blank line before the credits begin

        for (int i = 0; i < credits.length; i++) {

            // System.out.println() is Java's print() — it prints and moves to a new line.
            System.out.println("  " + credits[i]);

            // ── ADDING A DELAY ────────────────────────────────────────────────
            // Python:  time.sleep(1.2)    — one clean line, no questions asked.
            // Java:    Thread.sleep(1200) — milliseconds, and you must handle an exception.
            //
            // Why the try-catch? Thread.sleep() can be interrupted by the operating
            // system (e.g., if the user presses Ctrl+C). Java's compiler forces you to
            // acknowledge that possibility. You don't have to do much about it — but
            // you must prove you thought about it. That's Java's safety philosophy in action.
            //
            // Thread.currentThread().interrupt() is the correct cleanup: it re-flags
            // the thread so anything watching for interrupts upstream still sees it.

            try {
                Thread.sleep(1000);                       // 1000 ms = 1 second per line
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();       // restore interrupted status
            }
        }

        System.out.println();
        System.out.println("  [ end of credits ]");
        System.out.println();
    }
}

// ─────────────────────────────────────────────────────────────────────────────
// HOW TO COMPILE AND RUN THIS PROGRAM
//
// 1. Open a terminal (Command Prompt, PowerShell, or a terminal in VS Code).
// 2. Navigate to the folder containing this file.
// 3. Compile:   javac MovieCreditsDemoDriver.java
//    This creates MovieCreditsDemoDriver.class (the bytecode Java actually runs).
// 4. Run:       java MovieCreditsDemoDriver
//
// If you see "javac: command not found", you need to install a JDK (Java
// Development Kit). The compiler is not the same as the runtime.
//
// ─────────────────────────────────────────────────────────────────────────────
// PYTHON vs. JAVA — SIDE-BY-SIDE SUMMARY
//
//  Task                  Python 3                    Java
//  ─────────────────     ──────────────────────      ────────────────────────────────────
//  Declare an array      credits = [...]             String[] credits = {...};
//  Array length          len(credits)                credits.length
//  Loop                  for credit in credits:      for (int i = 0; i < credits.length; i++)
//  Access element        credits[0]                  credits[i]
//  Print a line          print(credit)               System.out.println(credits[i]);
//  Pause 1 second        time.sleep(1)               Thread.sleep(1000);  // + try-catch
//  Semicolons?           No                          Yes — every statement ends with one
//  Type declaration?     No                          Yes — every variable needs a type
//
// The concept — "iterate a list, do something with each item" — is identical.
// The syntax is different because Java and Python have different values.
// ─────────────────────────────────────────────────────────────────────────────
