Assignment 6, due Mar 1
Part of
the homework for CS:2820, Spring 2019
|
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!
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)
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)
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)