Questions on Assignment 3.5

Three questions I answered today

  • I don’t understand what Function1 and MandelbrotBase are supposed to do. Can you give an example?

    Objects conforming to Function1 are representations of single-valued functions whose argument and result types are the same. For example, the real-valued function f(x) = 3x could be represented as objects of the class

    class Tripler implements Function1<Double> {
      public Double apply(Double d) { return 3.0 * d; }
    }
    

    For example the statements

    final Tripler tr = new Tripler();
    System.out.println(tr.apply(2.3);
    

    should print 6.9.

    The MandelbrotBase class represents the family of functions fc from which the Mandelbrot set is generated. For example, consider f3+4i(x)=x2+(3+4i). Note that f3+4i(1+2i) = (1+2i)2 + (3+4i) = (1+4i-4)+(3+4i) = 8i. So if we execute the statements:

    final Function1<Complex> f3p4i = new MandelbrotBase(Complex.cpl(3,4));
    final Complex c = f3p4i.apply(Complex.cpl(1,2));
    System.out.println(c.getReal() + "+" + c.getImaginary());
    

    We would expect them to print 0+8i.

  • In the description of Function1Iterator, did you mean to describe next() instead of iterator?

    Yes. I’ve corrected the text to say: The first value returned by the next() method of a Function1Iterator should be initial, and then the result of f.apply(initial), then f.apply(f.apply(initial)), and so on. Implement a test class Function1IteratorTests to test an implementation of Function1Iterator.

  • What should the hasNext method do?

    Since we can always apply f another time, hasNext() will always return true.

  • May I submit additional classes which I use in my tests?

    Yes. Do remember the constraint that my tests of your JUnit code will provide alternate versions of MandelbrotBase.java and FunctionIterator.java which are variously buggy, so you expect those classes to deliver no more than the minimum described in the assignment spec.

  • What is this interface Iterator? Do I need to define it?

    No. Iterator is a standard class in the Java distribution; its JavaDoc page is here. It is in java.util (and not java.lang), so you will need to use

    import java.util.Iterator;
    

    at the start of your file, in between the file header comment and the class Javadoc.

See also: Assignment 3.5, CS220 homepage