Quadratic Upgrade 2  •  Java Showcase  •  09/23/2026
TNT | JavaQuadraticSaga — Upgrade 2

Quadratic Upgrade 2

Building on Upgrade 1. final constants, an explicit extends Object, axis of symmetry as a computed String ivar, memory address via super.toString(), and a live aliasing trap demonstration that shows exactly why new is not optional.

⬆ Upgrade from Upgrade 1

What Was Added

QuadraticDriver upgrades:

  • final added to all three constants — compiler enforces immutability
  • q4.printSummary() replaces System.out.println(q4.summary()) — demonstrates utility-calling-utility pattern
  • Copy constructor test enhanced: getMemoryAddress() comparison proves distinct objects
  • New Alias Trap section: q7 = q2 (no new!) shares the same address; q7.setC(666) silently mutates q2
  • Degenerate test promoted to q8 to free q7 for the alias demonstration

Quadratic class upgrades:

  • extends Object explicit — makes the implicit Java parent visible in code
  • axisOfSymmetry new String ivar — computed in computeVertex(), reported in summary()
  • memoryAddress new String ivar — set in every constructor via obtainMemoryAddress()
  • obtainMemoryAddress() new utility — calls super.toString() to capture the JVM address string
  • printSummary() new utility — wraps summary() so the caller only needs one line
  • getAxisOfSymmetry(), getMemoryAddress() new getters

OrderedPair & ComplexOrderedPair:

  • Unchanged from Upgrade 1 — all additions are in the driver and Quadratic.java

QuadraticDriver.java — The Command Center

Two major additions: final on every constant, and the aliasing trap demonstration. The copy constructor test now compares memory addresses to prove objects are distinct. The alias test uses q7 = q2 (no new!) to show that both variables reference the same object — and that mutating one silently changes the other.

Key Changes from Upgrade 1

  • final keyword on SHOULD_SHOW_BREADCRUMBS, DF, EPSILON — prevents accidental reassignment
  • q4.printSummary() — the commented-out println(q4.summary()) shows the old approach side-by-side
  • Copy constructor section uses getMemoryAddress().equals(...) to verify distinct identity
  • Alias section: q7 = q2 → same address proven → q7.setC(666) → q2 is silently corrupted
The Aliasing Trap: Quadratic q7 = q2; does NOT create a new object. It copies the reference (memory address), not the data. Both q7 and q2 now point to the same spot in memory. Changing one changes both. Use new Quadratic(q2) when you need an independent copy.
QuadraticDriver.java Java · File 1 of 4

    OrderedPair.java — The Foundation Unchanged from Upgrade 1

    No structural changes from Upgrade 1. Included here for completeness so the four-file project is self-contained. DF.format() in toString() and breadcrumbs throughout remain as they were.

    No Changes from Upgrade 1

    • All additions in this upgrade are confined to QuadraticDriver.java and Quadratic.java
    • This file is included so the four-file set is complete and runnable as-is in JDoodle
    OrderedPair.java Java · File 2 of 4

      ComplexOrderedPair.java — The Subclass Unchanged from Upgrade 1

      No changes. extends OrderedPair, overridden toString() for a + bi notation, conjugate() and modulus() remain exactly as in Upgrade 1.

      No Changes from Upgrade 1

      • Polymorphic toString() dispatch still drives getRootsDescription() — no changes needed
      • Included here for the complete four-file project
      ComplexOrderedPair.java Java · File 3 of 4

        Quadratic.java — The Full PCNICOTGSU Blueprint

        The main additions are here. extends Object is now explicit. Two new String ivars — axisOfSymmetry and memoryAddress — make the object more self-aware. obtainMemoryAddress() uses super.toString() to capture the JVM’s identity string, which the driver then uses to prove whether two variables point to the same object or not. See the analysis page for a deep dive into every decision.

        Key Changes from Upgrade 1

        • extends Object explicit declaration — pedagogical bridge to super.toString()
        • axisOfSymmetry new private String ivar — set inside computeVertex() as "x = " + DF.format(h)
        • memoryAddress new private String ivar — set in every constructor via obtainMemoryAddress()
        • obtainMemoryAddress() new utility — returns super.toString() which produces Quadratic@1a2b3c4d
        • printSummary() new public utility — calls summary() and prints result; utility calling a utility
        • summary() expanded to include axis of symmetry and memory address output
        • getAxisOfSymmetry() and getMemoryAddress() new getters
        Quadratic.java Java · File 4 of 4 · PCNICOTGSU annotated