// ComplexOrderedPair EXTENDS OrderedPair
// Reinterprets x as the real part and y as the imaginary part
// of a complex number a + bi.
//
// Key OOP concepts demonstrated:
//   extends     — inherits all OrderedPair fields and methods
//   super()     — calls parent constructor from child
//   @Override   — replaces the parent's toString with complex notation
//   new methods — conjugate() and modulus() are added behavior
public class ComplexOrderedPair extends OrderedPair {

    // default constructor: 0 + 0i
    public ComplexOrderedPair(){
        super();                // calls OrderedPair()
        setLabel("z");
        System.out.println("...ComplexOrderedPair default constructor...");
    }

    // two-parameter constructor: real + imagi
    public ComplexOrderedPair(double real, double imaginary){
        super(real, imaginary); // calls OrderedPair(x, y)
        setLabel("z");
        System.out.println("...ComplexOrderedPair two-parameter constructor...");
    }

    // copy constructor
    public ComplexOrderedPair(ComplexOrderedPair orig){
        super(orig.getX(), orig.getY()); // super needs getters — orig.x is private!
        setLabel(orig.getLabel());
        System.out.println("...ComplexOrderedPair copy constructor...");
    }

    // @Override toString — shows a+bi notation instead of (real, imag)
    @Override
    public String toString(){
        double r = getX();   // getX() inherited from OrderedPair
        double i = getY();   // getY() inherited from OrderedPair
        if (i == 0)  return "" + r;
        if (r == 0)  return i + "i";
        if (i > 0)   return r + " + " + i + "i";
        return r + " - " + Math.abs(i) + "i";
    }

    // conjugate: flip the sign of the imaginary part
    public ComplexOrderedPair conjugate(){
        System.out.println("...conjugate...");
        return new ComplexOrderedPair(getX(), -getY());
    }

    // modulus — same value as absVal (√(r²+i²)), meaningfully renamed
    public double modulus(){
        return getAbsVal();   // getAbsVal() inherited from OrderedPair
    }

}//end class ComplexOrderedPair
