Pages

Keep Portland Weird!

interface Program
{
    void entryPoint(String... args);
}

abstract class AbstractProgram implements Program
{
    protected AbstractProgram(String[] args)
    {
        this.entryPoint(args);
    }
}

// MISSING CLASS: FirstProgram
class FirstProgram extends AbstractProgram
{
    public FirstProgram(String[] args)
    {
        super(args);
    }
    public void entryPoint(String... args)
    {
        for (String arg: args) System.out.print(arg);
    }
}

class SecondProgram extends FirstProgram
{
    public SecondProgram(String[] args)
    {
        super(args);
    }
    public void entryPoint(String... args)
    {
        // MISSING CODE

        int i = 0;
        for (String s1 : args)
            for (String s2 : args)
                super.entryPoint("Number " + ++i + ": ", s1, s2);
    }
}

class Main
{
    public static void program(String... args)
    {
        new FirstProgram(args);
        new SecondProgram(args);
    }
}

/** ProgressiveProgram should print:
 *  KEEP PORTLAND WEIRD!
 *  Number 1: KEEP KEEP Number 2: KEEP PORTLAND Number 3: KEEP WEIRD!
 *  Number 4: PORTLAND KEEP Number 5: PORTLAND PORTLAND Number 6: PORTLAND WEIRD!
 *  Number 7: WEIRD!
 *  KEEP Number 8: WEIRD!
 *  PORTLAND Number 9: WEIRD!
 *  WEIRD!
 */
public class ProgressiveProgram
{
    public static void main(String args[])
    {
        Main.program("KEEP ", "PORTLAND ", "WEIRD!\n");
    }
}

Programming Exercises

  1. Compose FirstProgram (the missing class).
  2. Supply the code that is missing from SecondProgram.entryPoint. Use exactly three semicolons.

Questions

  1. What is the order of growth of the running time of FirstProgram.entryPoint as a function of its inputs?
  2. What is the order of growth of the running time of SecondProgram.entryPoint as a function of its inputs?

Your choices are:

  1. constant
  2. logarithmic
  3. linear
  4. linearithmic
  5. quadradic
  6. cubic
  7. exponential
  8. conservative
  9. liberal
  10. progressive
  11. weird