Duke Computer Science Shield

CompSci 201: Data Structures & Algorithms

Spring 2013
Duke University Computer Science

Recitation 4: Jotto

February 1, 2013

For this recitation you will be submitting:
  • Common.java
  • ListRemove.java
  • Recitation4.txt

Part 1:

There is a new APT posted on the APT site, Common. This APT should remind you of some of the code you need for Jotto. In fact, once you get this working you can just copy and paste your APT code into your Jotto assignment! Start by working with a partner to solve this APT.

Part 2:

Snarf the code for Recitation 4.

ListRemove reads in a list of words from a text and removes all of the words that begin with the letter a. Run the code and make sure that you understand what it is doing.

Try running the code with fruit2.txt instead of the file fruit1.txt. In your Recitation4.txt file, explain why the code does not work for fruit2.txt but does work for fruit1.txt.

There are a few different ways of fixing this problem, two of which are described below. You should complete at least 2a before the end of recitation.

Part 2a: Create a temporary list

Create a new method removeFromListGood

  • Create a temporary ArrayList. This list will hold all of the values that you do not want to remove.
  • Loop through your original list and add all of the values that you do not want to remove (i.e. do not start with "a") into your temporary list.
  • Set your original list to your temporary list--the list that does not have any words that start with "a."

Part 2b:Use the Iterator

Add the method removeFromListIterator that uses Java's built in Iterator to loop through your list. See the Java documentation for more information.

Don't forget to submit your code!