Assignment 7, due Mar 8

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: Consider this bit of code involving Java Lambda expressions:
    ClassA x = (int i) -> i + 1;
    ClassB y = (ClassA j, int k) -> j.f( j.f( k ) );
    int    z = y.g( x, 1 );
    

    a) What is the value of z? (0.5 points)

    b) Give the appropriate definition for ClassA. (0.5 points)

    c) Give the appropriate definition for ClassB. (0.5 points)

  2. Background: Up to to and including RoadNetwork version 2019-03-01, the ScanSupport.nextLine() method used sc.nextLine() to skip and return the remainder of the current line. This would throw an exception if the last line of the file did not end with a newline.

    The revised version 2019-03-04, based on the solution to Homework 6, used sc.skip(theRest) followed by sc.match().group(0) to get and return what was skipped.

    This change works despite the fact that sc.nextLine() and sc.skip(theRest) leave the scanner in different states.

    a) What is the difference in the scanner state? (0.5 points)

    b) Why does this difference in scanner state have no impact on the behavior of the rest of the program? (0.5 points)

  3. Background: Lectures 21 and 22 introduce the concept of a pending event set for discrete event simulation. In Lecture 22, the class PriorityQueue is used, but Java's standard library contains other classes that might also be used to do this job. (Part of the problem is that PriorityQueue should almost certainly be an abstract class with many implementations, but they locked down the name with one implementation.)

    A problem: What are some other classes in the Java library that could be used? (0.5 points)

    Suggestion: Hunt through the Java documentation starting at PriorityQueue looking at the interfaces it implements and the other methods that implement those interfaces.