Programming Assignment 03: Working with Lists

Estimated reading time: 5 minutes
Estimated time to complete: 60–120 minutes (plus debugging time)
Prerequisites: Assignment 01
Starter code: working-with-lists-student.zip
Collaboration: not permitted

Overview

In this assignment, you’ll practice working with lists in two contexts. First, you’ll write a series of static methods that interact with List objects. Then, you’ll extend the ArrayList class, adding new instance methods to a subclass.

We’ve provided a large set of unit tests to help with automated testing, though you might also want to write a class with a main method for interactive testing. The Gradescope autograder includes a few more tests, but they exist primarily to verify you’re not gaming the autograder. If your code can pass the tests we’ve provided, it is likely correct.

Goals

  • Practice interacting with the List abstraction.
  • Practice writing static methods.
  • Practice writing instance methods.
  • Translate written descriptions of behavior into code.
  • Test code using unit tests.

Downloading and importing the starter code

As in previous assignments, download and save (but do not decompress) the provided archive file containing the starter code. Then import it into Eclipse in the same way; you should end up with a working-with-lists-student project in the “Project Explorer”.

What to do

There are two files that you need to open and complete.

First, open src/list/exercises/StringExercises.java. This file is contains a set of static methods and documentation describing them. Implement each method as described. Some hints:

  • Remember to consider the cases of empty lists and empty strings.
  • For split, you can use the String.split method as follows to get an array of the words: String[] words = s.split("\\s+");.
  • For allCapitalizedWords, you may find Character.isLetter helpful.
  • For insertInOrder, you can use String.compareTo to determine which string comes first. If you have two strings s1 and s2, use s1.compareTo(s2) < 0 to check if s1 “comes before” s2.
  • If a list cannot be modified, then you’ll have to create a new list to work on.

Then, open src/list/exercises/ExtendedArrayList.java. This file describes a class that extends (that is, subclasses) ArrayList, adding several instance methods. Implement each method as described. Remember, these methods are instance methods. They are operating on the current instance (this) of the ExtendedArrayList. You can call methods like size() directly.

One more note: We will not test your code on inputs that are not described by the documentation. For example, all of the list parameters are described as “non-null”, so you shouldn’t write code to handle the case of a null value being supplied as one of these parameters.

Submitting the assignment

When you have completed the changes to your code, you should export an archive file containing the entire Java project. To do this, follow the same steps as from Assignment 01 to produce a .zip file, and upload it to Gradescope.

Remember, you can resubmit the assignment as many times as you want, until the deadline. If it turns out you missed something and your code doesn’t pass 100% of the tests, you can keep working until it does.