Quadratic Upgrade 4  •  Java Showcase  •  10/07/2026
TNT | JavaQuadraticSaga — Upgrade 4

Quadratic Upgrade 4

Seven improvements in one upgrade: InvalidRootsException replaces System.exit(), constructor chaining delegates the monic case, non-monic scaling unlocks any-a roots, toString() suppresses zero and ±1 coefficients, the t-table loop uses integer indexing, and compareTo() orders quadratics by vertex height.

⬆ Upgrade from Upgrade 3

What’s New in Upgrade 4

QuadraticDriver changes:

  • File count is now 5 because InvalidRootsException.java is brand new
  • final is restored on the shared constants from Upgrade 2
  • Every roots-constructor demo is wrapped in try/catch so the program can recover gracefully
  • Six driver test sections now showcase output cleanup, monic roots, non-monic roots, complex roots, bad-input survival, and compareTo()

Quadratic.java changes:

  • Constructor chaining turns the monic roots constructor into a one-line shortcut
  • New non-monic constructor supports any non-zero scale factor a
  • initFromRoots() centralizes validation + coefficient computation
  • InvalidRootsException replaces System.exit(0) in the roots constructors
  • toString() suppresses zero and ±1 coefficients, printOrderedPairsIn() uses integer indexing, and compareTo() orders by vertex height

Note: OrderedPair and ComplexOrderedPair are unchanged from Upgrade 3; the engineering lift happens in the driver, the new exception file, and Quadratic.

Want to see what all five files produce when you run them? No upload required.

QuadraticDriver.java — The Test Bench: Six Scenarios

Upgrade 4 turns the driver into a recovery-first demonstration. Every roots-constructor path is tested, the invalid complex case is caught instead of crashing the JVM, and the final section introduces vertex-height ordering through compareTo().

Key Changes from Upgrade 3

  • final is restored on the three shared constants
  • All roots-constructor calls now use try/catch with InvalidRootsException
  • New non-monic roots test shows Quadratic(3.0, r1, r2) building 3x² - 21x + 30
  • Test 5 proves the program survives invalid input and continues to Test 6
QuadraticDriver.javaJava · File 1 of 5

    InvalidRootsException.java — The New Safety Net Brand-New 5th File

    This is the philosophical center of Upgrade 4. Instead of dropping the trapdoor with System.exit(0), the code now throws a checked exception and lets the caller decide how to respond.

    Brand New File — A Custom Checked Exception

    • Extends Exception (checked) — forces callers to acknowledge the error
    • Single constructor passes message to super(), retrievable via getMessage()
    • Replaces System.exit(0) in the roots constructors of Quadratic.java
    • The driver demonstrates survival: the program continues after catching it
    InvalidRootsException.javaJava · File 2 of 5

      OrderedPair.java — Still the Foundation Unchanged from Upgrade 3

      No changes here, and that is a feature rather than a bug. The same x/y storage model continues to support both real ordered pairs and the complex subclass.

      No Changes from Upgrade 3

      • OrderedPair still provides the shared real/imaginary storage model used everywhere else
      • The getters remain essential for subclass-safe access to private data
      • Included so the full five-file project is complete and runnable as-is
      OrderedPair.javaJava · File 3 of 5

        ComplexOrderedPair.java — Complex Arithmetic Holds Steady Unchanged from Upgrade 3

        Upgrade 3 already placed the right arithmetic on the right class. Upgrade 4 keeps that work intact and simply relies on it from the new non-monic constructor path.

        No Changes from Upgrade 3

        • add() and multiply() still provide the complex-number math used by the roots constructors
        • The subclass remains the correct home for conjugate arithmetic and formatted complex output
        • Keeping this file unchanged shows that Upgrade 3’s design placement was already sound
        ComplexOrderedPair.javaJava · File 4 of 5

          Quadratic.java — All Seven Improvements

          Upgrade 4 does not add harder math; it adds engineering quality. Constructor chaining removes duplication, the non-monic path generalizes the roots constructor, checked exceptions replace JVM termination, output gets polished, loops get safer, and comparison logic now mirrors Java’s standard-library convention.

          Key Changes from Upgrade 3

          • New non-monic roots constructor Quadratic(double a, OrderedPair r1, OrderedPair r2)
          • Private helper initFromRoots() centralizes validation + coefficient computation
          • throw new InvalidRootsException(...) replaces fatal termination in the roots path
          • toString() now suppresses zero and ±1 coefficients using StringBuilder
          • printOrderedPairsIn() now uses integer indexing, and compareTo() compares vertex height
          Constructor Chaining: this(1.0, r1, r2)
          The monic constructor delegates entirely to the non-monic with one line.
          this(...) must be the FIRST statement in a constructor body.
          This avoids duplicating all the validation and coefficient-computation logic.
          Quadratic.javaJava · File 5 of 5