Assignment 6, due Mar 4

Part of the homework for CS:2820, Spring 2016
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of lecture on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!

  1. Background: Consider the problem in MP3 of recognizing the - token that means that a synapse has no name. Assume this declaration:
    static final Pattern dash = Pattern.compile( "-" );
    

    Now consider these two approaches to identifying whether the next token is a dash:

    if (sc.hasNext( "-" )) ...
    if (sc.hasNext( dash )) ...
    

    a) What is the advantage of using a Pattern instead of just a string. (0.3 points)

    b) If either hasNext() is true, how do you skip over the token it found? (0.3 points)

    c) Why not just use name=sc.next() and then ask if name is "-"? (0.3 points)

  2. Background: Consider the options of setting the name field of a synapse to null with storing the value - to signal a missing name.

    a) Note that most synapses will be anonymous. How many different strings equal to "-" will the code store if you just say name=sc.next() and then keep the string it returns as the name, regardless? (0.3 points)

    b) If you use null to represent missing names, how does that complicate the synapse's toString() method? (0.3 points)

  3. Background: For MP3, you must deal with both named neurons and some named synapses. There are two ways to handle this:

    a) Assuming you have a findName() method in the one-list scheme, and it returns either an object o or null if there no object had the given name. Write code to make the 3-way determination whether o is null, a synapse or a neuron. (0.5 points)

    b) If you want to keep just one list with the simplest possible code for findName(), what should be the relationship between classes Neuron and Synapse (they were totally unrelated in MP2). Do not give code. One carefully thought out sentence will answer this question. (0.5 points)

    c) Which of the above schemes (one-list or two-list) would be the easiest to use in the context of the code you already have for MP2? Explain your reasoning. (0.5 points)