Source code for

What follows is the highlighted source code with comments. You can also download this file directly:

/* This work by W. Patrick Hooper <> is free of known copyright restrictions.
 * The work is in the public domain.
 * Author's website: <a href=""></a>. 
package geometry;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import number.Complex;

 * This class is meant to demonstrate the PlanarMap interface.
 * @author W. Patrick Hooper
public class ComplexPolynomial implements PlanarMap {
    private List<Complex> coefficent_list;
    /** Creates a polynomial from a list of coefficients in order of increasing
     * degree. Note that the ellipsis (...) indicates that the parameters
     * are a list of complex numbers. For instance, this can be called
     * with "new ComplexPolynomial(a0,a1,a2)" to construct the polynomial
     * "a0+a1*z+a2*z^2."
    public ComplexPolynomial(Complex ... coefficients){
        // In this constructor, coefficients can be accessed as an array.

    /** Evaluate the polynomial at z. */
    public Complex map(Complex z) {
        Complex power=new Complex(1);
        Complex sum=new Complex(0);
        // Below is a for each loop. 
        // It iterates over all the coefficients in order.
        for ( Complex coef : coefficent_list ) {
        return sum;
    /** Return a string describing the polynomial as a map of the Complex plane. */
    public String toString() {
        StringBuilder sb=new StringBuilder();
        sb.append("z -> ");
        Iterator<Complex> it=coefficent_list.iterator();
        if (! it.hasNext()) {
            return sb.toString();
        if (! it.hasNext()) {
            return sb.toString();
        sb.append(" + ""*z");
        int deg=2;
        while (it.hasNext()) {
            sb.append(" + ""*z^"+deg);
        return sb.toString();
Last modified on August 25, 2021.
[check html] [check css]