Homework 3

Homework 3

Homework Reflection SurveyGradescopeStarter Code
Due: Thursday October 02, 2025 5:00PM
Goals:
  • Implement your own version of an ArrayList.
  • Consult Oracle's documentation of an ArrayList.
Submit these files:ArrayListString.java

In this assignment, you will implement your own version of an ArrayList.

Testing your implementation

You should write comprehensive test cases in the main method of ArrayListString.java. These are the requirements you must meet in your test cases:

  • ArrayList size is checked
  • ArrayList remove is called
  • ArrayList indexOf is called
  • ArrayList isEmpty is called
  • at least 5 elements are added to an ArrayList
  • ArrayList get is called
  • ArrayList set is called
  • ArrayList is cleared
  • ArrayListString is initialized

This is listed as the first part of the assignment because I’d like you to get in the habit of writing test cases while or even better before you write your code! If you write tests before you write your code, you are practicing test driven development. This is useful because you’ll (a) think through what the effect of each method should be before starting to write it and (b) have a set of test cases ready to debug your implementation as needed.

Implementing your ArrayList

Please prepare for implementing your ArrayList by reviewing the slides from Lecture 3R for the concepts we used to design a DIYList.

Instead of parametrizing our version of an ArrayList in terms of any type of stored item, we’ll only store Strings. So we will call this class ArrayListString and we will not use generics in this assignment.

The initial template is quite minimal and only sets up the ArrayListString with the items and size fields, as well as the capacity() method. Your job is to implement the methods listed below which should match the descriptions in the official ArrayList documentation. You don’t need to implement all the methods defined for an official ArrayList, just the ones listed below.

Although the capacity() method is not specified in the official ArrayList documentation, we’re adding it to our version since it may be useful for testing (and the Gradescope tests will also check the capacity).

Also, the official ArrayList implementation is supposed to throw exceptions if an index is out of bounds. We haven’t talked about exceptions so you don’t need to check the bounds of the indices passed to certain methods. The Gradescope tests will always pass valid indices (0 <= index < size()).

Here are the methods you need to implement. The description you need to follow is linked in each method name below.

Warning

To earn any credit on this assignment, you must have an implementation of every required method. It does not need to be a correct working implementation, but you should provide at least a stub that returns a valid value, e.g.,

public boolean isEmpty() {
  return false;
}

I recommend that this is the first thing that you do when starting the homework!

If you use java.util.ArrayList or another existing list implementation in your code, you will not get credit.

Documentation, Style, and Design

Style

This assignment offers an opportunity to get used to feedback from the checkstyle style checker before it counts towards your grade. I’d strongly encourage you to get checkstyle set up in VS Code and to ensure that you do not have checkstyle errors in your final submissions on Gradescope (these are reported along with the results of other test cases).

Checkstyle is configured on Gradescope to use the Google Java Style Guide. The rules are a superset of what we introduced in class. See this page for details on how to use checkstyle.

Documentation

In addition to style, checkstyle will check that you have written comprehensive documentation, which you should add to each method. To create a javadoc documentation comment, type /** right above one of your methods and then hit the Enter (or return) key. VS Code should autofill a javadoc-style documentation as in the animation below:

The documentation you add for each method should include three main components: (1) a short sentence describing what the function does, (2) a brief description of each parameter using @param and (3) what the method returns using @return. When describing each @param, it’s also good practice to describe any limitations on the parameters.

Design

Checkstyle will check for style and documentation; I will do a manual review for design. Up to 5% may be deducted from your final score due to design problems. This will also include checking the quality (rather than just the form) of your javadoc comments!