Assignment 4, due Sep 15

Part of the homework for CS:2820, Fall 2017
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. 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 the following two Java code fragments. Rewrite each of them a while loop instead of a for loop. (0.5 points each)

    a)

    System.out.println( "Start" );
    for (int i = 1; i < 10; i++) {
        System.out.println( "i = " + i );
    }
    System.out.println( "End" );
    

    b)

    for (Road r:roads) {
        System.out.println( r.toString() );
    }
    

  2. Background: There are always alternative solutions to any programming problem. The code suggested in the notes keeps the list of all roads and all intersections in the main program's class. We could have had class Road keep the list of all roads, and class Intersection keep the list of all intersections. Assume we want to do this, and that we make these lists private. This suggests that class Intersection should export a static method for looking up a road by name instead of having this search method in the main class..

    a) Give an appropriate declaration for the list of roads inside class Road. (0.3 points)

    b) Give the code you would use inside the Road constructor so that the constructed road automatically adds itself to the list. (0.3 points)

    c) The main class still needs to iterate over all the roads in order to print out the textual representation of the road network. Suggest how class roads could permit this without exporting the list itself. (0.4 points)

  3. Background: Consider the problem of designing test data to test the linear search version of findIntersection given in Lecture 7, using a path-testing methodology.

    a) Identify all of the distinct paths through this code. (0.5 points)

    b) Describe how you could test these paths using input to the road-network program. Merely giving the input file(s) is not sufficient without an explanation of how what each input file or each input line tests. (0.5 points)