Assignment 7, due Mar 10

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

On every assignment, write your name and section number. Write your name as it appears on your university ID card! Use the section number as it appears in your current registration! We will not do detective work to figure out who did what. Homework is due on paper at the start of your discussion section. Exceptions will be made only by advance arrangement with your TA (excepting "acts of God"). Never push homework under someone's door!

  1. Background: The code distributed with Lectures 18 and 19 on March 1 and 3 contains ScanSupport.nextName() for pulling a name from the input line without crossing line boundaries the way sc.next() does. The code continues to use sc.nextFloat(), though, and as a result, it sees nothing wrong with this input:
    road A B
             1.5 -- this is on the next line!
    

    a) Give a regular expression that recognizes floating-point numbers such as 1, 12, 12.3, 12.34 and .345 (ignore exponential notation). (0.5 points)

    b) Write a method ScanSupport.nextFloat() patterned after the existing nextName routine that returns a floating-point value if there is one or the special value Float.NaN if there isn't. (0.5 points)

  2. Background: All of the ScanSupport methods take a parameter sc, for example ScanSupport.nextName(sc). It would be nicer to write sc.nextName().

    a) Describe how to use Java's class hierarchy to permit the above change. (Do not write code to answer this, write a description of hierarchic class relationships.) (0.5 points)

    b) How would the the header for Intersection.newIntersection() have to be changed to allow use of this new form. (0.5 points)

  3. Background: On the exam, it was suggested that the keyword private could usually be deleted without causing any problems. Note the word usually. There are exceptions that occur when there is a class hierarchy and the parent class contains a private final method.

    A problem: Construct a small example that demonstrates this. It can be done in 10 lines of totally useless code. (1.0 points)