What’s New in Upgrade 3
QuadraticDriver changes:
- Removed
finalfrom the three shared constants — a regression from Upgrade 2, and a good reminder that it should be restored - Two new constructor tests: one from real roots, one from a complex conjugate pair
- T-table output added through
printOrderedPairsIn() - DWR:
xmin,xmax, andxincare reused correctly without being re-declared
Class changes:
Quadratic: new roots constructorQuadratic(OrderedPair r1, OrderedPair r2)Quadratic:printOrderedPairsIn()adds a reusable t-table generatorQuadratic:isEffectivelyZero()promoted topublicComplexOrderedPair:add()andmultiply()support conjugate-root arithmeticOrderedPair: unchanged from Upgrade 2
QuadraticDriver.java — The T-Table Challenge
Upgrade 3 turns the driver into a two-part showcase: first a quadratic built from two real roots, then one built from a complex conjugate pair. The driver also demonstrates the new t-table printer and includes a DWR about reusing local variables instead of re-declaring them.
Key Changes from Upgrade 2
- Two new quadratic tests centered on the roots constructor: one real, one complex
printOrderedPairsIn()demo prints around the vertex in two output formats- DWR note calls out proper variable reuse for
xmin,xmax,xinc finalwas removed from the constants — a regression worth discussing on the analysis page
OrderedPair.java — Still the Foundation Unchanged from Upgrade 2
No structural changes here. That matters: Upgrade 3 gets its new power by combining the existing
OrderedPair foundation with smarter constructors and smarter complex arithmetic elsewhere.
No Changes from Upgrade 2
OrderedPairstill provides the shared real/imaginary storage model used by the subclass- Included here so the four-file project remains complete and runnable as-is
ComplexOrderedPair.java — Complex Arithmetic Arrives
This is the enabling upgrade. Without add() and multiply(), the quadratic roots constructor
could not compute real coefficients from a complex conjugate pair. Upgrade 3 makes the subclass do the math that belongs to complex numbers.
Key Changes from Upgrade 2
add()added for component-wise complex additionmultiply()added using FOIL and the identityi² = -1- Comments walk through the algebra explicitly at APCS level
- The copy constructor still models the correct use of getters for private superclass fields
Quadratic.java — The Roots Constructor
Upgrade 3 flips the usual workflow inside out. Instead of starting with a, b, and c
and solving for roots, the new constructor starts with roots and reconstructs the quadratic. That demanded Vieta’s Formulas,
a defensive programming gate, a t-table generator, and one excellent DWR about cast operator precedence.
Key Changes from Upgrade 2
- New roots constructor handles both real roots and complex conjugate roots
- Defensive validation checks the inputs before any coefficient computation happens
printOrderedPairsIn()generates a t-table over a caller-chosen intervalisEffectivelyZero()is now public so outside inputs can be validated cleanly- DWR comment documents the cast trap around subclass-only method calls
(ComplexOrderedPair)r1.multiply(...) tries to call multiply() on an
OrderedPair reference. Java parses it as: cast the result, not the receiver.Fix: store the downcast first —
ComplexOrderedPair z1 = (ComplexOrderedPair) r1;