Homework 3

Homework 3

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

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

Implementing stubs

Please prepare for implementing your ArrayList by reviewing the slides from Lecture 4T 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 will need to implement. The description you need to follow is linked in each method name below.

Start by writing stubs for all of your methods. They should have the final method signature and return a placeholder value of the correct type. For example, for add:

public boolean add(String item) {
  return true;
}

This will allow you to write tests and enables the code on Gradescope to compile properly! The starter code for the programming exam also includes stubs, if you are unfamiliar with the concept.

Warning

Having at least a stub for each required method is necessary to earn any credit on this assignment! Make sure your stubs compile before you do anything else.

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

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:

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

These requirements are listed before the implementation 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

Now, implement each method according to the descriptions above. Run your tests after each change you make to confirm that each method does what you expect!

Documentation, Style, and Design

Style

This is the first assignment where the checkstyle style checker will count towards your grade. 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 and how checkstyle violations are incorporated into your score.

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 checks for style and (some) 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!