What’s New in Upgrade 4
QuadraticDriver changes:
- File count is now 5 because
InvalidRootsException.javais brand new finalis restored on the shared constants from Upgrade 2- Every roots-constructor demo is wrapped in
try/catchso 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 computationInvalidRootsExceptionreplacesSystem.exit(0)in the roots constructorstoString()suppresses zero and ±1 coefficients,printOrderedPairsIn()uses integer indexing, andcompareTo()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
finalis restored on the three shared constants- All roots-constructor calls now use
try/catchwithInvalidRootsException - New non-monic roots test shows
Quadratic(3.0, r1, r2)building3x² - 21x + 30 - Test 5 proves the program survives invalid input and continues to Test 6
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 viagetMessage() - Replaces
System.exit(0)in the roots constructors ofQuadratic.java - The driver demonstrates survival: the program continues after catching it
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
OrderedPairstill 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
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()andmultiply()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
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 pathtoString()now suppresses zero and ±1 coefficients usingStringBuilderprintOrderedPairsIn()now uses integer indexing, andcompareTo()compares vertex height
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.