Assignment 11, due Apr 22

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

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of lecture on the day indicated. Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!

  1. Background: Problem 4 on exam 2 asked you to implement a subclass of LinkedList that added one new method finalize(). By default, objects of this class behave exactly like objects of class LinkedList. Once finalized, an object of this new class is fixed, in the sense that the order and identities of the list elements cannot be changed. Here, let's call the new class FinalizableList.

    Assume for the purpose of this problem that class LinkedList has only the following methods: get(int index), set(int index,E element), push(E element), size(E element), clear(), plus one initializer, LinkedList(). files as a starting point for your solution to MP5.

    A problem: Give a complete and syntactically correct Java code for class FinalizableList. No comments, but make it readable. (1.0 points)

  2. Background: Focus just on the set() method above. This has two parameters, but it is possible to redesign the class interface to support a programming style that used just one parameter per method call.

    A problem: Give Java code that you could add to your class defined above to define a pair of new methods, setI(int index), and setE(E element), such that a call to o.set(i,e) can be replaced with o.setI(i);o.setE(e). If you have to declare new fields of class FinalizableList to do this, feel free to declare them as needed. (1.0 point)

  3. Background: In class on Monday April 18, we discussed an alternative simulation framework and gave an example, converting class Road to use the new framework.

    A problem: Rewrite the lightChanges method from Exam 2 problem 3 to use this new framework. (1.0 points)