Assignment 6, due Mar 1

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

Assignments are to be turned in on paper. On every assignment, write your name, course and section number at the top of each page. Write your name as it appears in your university records! Use the section number for which you are registered! We will not do detective work to figure out who did what. Work must be legible.

Homework is due on paper in discussion section, usually at the start except when the assignment indicates that time to work on the assignment will be provided in class. Exceptions will be made only by advance arrangement with your TA (excepting "acts of God" outside your control). Never push homework under someone's door!

  1. Background: MP3 has a number of requirements.

    A problem: List all of the new classes must you add to a solution of MP2 to make a good solution to MP3. For each class, give a one line description appropriate for use as the first line of a Javadoc comment. (0.5 points)

  2. Background: In class, we developed this bit of code to clean up at the end of line after each command. Note, all the comments have been deleted.
    public static void nextLine( Scanner sc, String msg ) {
        final String remainder = sc.nextLine();
        if (remainder.equals( "" )) return;
        if (remainder.startsWith( "--" )) return;
        Errors.warn( msg + ": " + remainder );
    }
    

    A problem: This code is broken. It does not properly handle lines with trailing blanks, it cannot recognize comments, and it throws an exception if it sees an ill-formed last line of a file (a line with no trailing newline character). Fix it!

    Hint: The Scanner class has some really useful methods called skip, and you will want to use your fixed code in your solution to MP3. (1.0 points)

  3. Background: The notes for Lecture 18 discuss anonymous classes and objects. Anonymous classes may be a new idea, but we have been dealing with anonymous objects for a while, that is, objects that are not directly bound to named variables. There are several examples of anonymous objects in the code distributed on Feb. 15.

    a) Identify all of the anonymous objects that are instantiated in the main method. (0.5 points)

    b) Rewrite the relevant part of the main method so that each of the anonymous object is bound to an appropriately named variable, declared as local to the point use as is reasonable. The purpose of this exercise is to drive home how anonymity can sometimes make code a bit more compact and readable. (0.5 points)

  4. A short question: Is it legal to declare class ScanSupport in our running example as an interface instead of a class? Explain the consequences of doing so. (0.5 points)