Classwork 4
Today, you'll be adding some methods to the IntArrayList class we started in... well... class!
GitHub Classroom + Skeleton
Start with the solution skeleton in-hand! The following will also serve as your submission mechanism (see submission instructions below).
Classwork 4 - GitHub Classroom
Specifications
Implement the following methods. You may add any private helper methods you like, but do not add any fields nor modify the public interface.
Method |
|---|
|
Adds the given int toAdd to the first position (0 index) in the IntList, preserving the relative order of other ints preexisting in the IntList.
// Example:
@Test
public void testPrepend() {
arr.prepend(1);
assertEquals(1, arr.getAt(0));
arr.prepend(2);
assertEquals(2, arr.getAt(0));
arr.prepend(3);
assertEquals(3, arr.getAt(0));
arr.append(0);
assertEquals(3, arr.getAt(0));
}
|
|
Inserts the given int toAdd at the specified index within the IntList. If there are any ints at indices The index parameter is defined for the range For any indexes outside of this range,
// Example:
@Test
public void testInsertAt() {
arr.append(1);
arr.append(2);
arr.append(3);
arr.append(4);
arr.append(5);
arr.insertAt(-1, 3);
arr.insertAt(-2, 3);
arr.insertAt(-3, 3);
assertEquals(3, arr.getAt(2));
assertEquals(-3, arr.getAt(3));
assertEquals(-2, arr.getAt(4));
assertEquals(-1, arr.getAt(5));
assertEquals(4, arr.getAt(6));
}
|
|
Removes all instances of the given int If the given int toRemove does not exist in the IntList, do nothing and return (i.e., *do not* throw any exceptions).
// Example:
@Test
public void testRemoveAll() {
arr.append(0);
arr.append(0);
arr.append(0);
arr.append(0);
assertEquals(4, arr.size());
arr.removeAll(0);
assertEquals(0, arr.size());
}
|
Notes
Because we're just getting our feet wet with designing data structures, I've given you all of the grading tests you'll need to pass for this assignment!
You are, of course, always free to add tests that help you diagnose where things might be going wrong in your code, but to receive full credit here, simply pass all of the given tests!
Not sure where to start? Look at how the other methods are implemented from what we did in class as inspiration!
Note also that you're allowed to *call* other methods we designed in class as part of your implementation if it makes sense to do so -- keep that code DRY!
Submission
You will be submitting your assignments through GitHub Classroom!
What
Complete all classes that accomplishes the specification above, in the project structure given in the skeleton above.
How
To clone this assignment (if you need a refresher), consult the guide here:
To submit this assignment:
Simply push your final, submission copy to the GitHub Classroom repository associated with you or your group.
If you worked in a group (3 individuals maximum), ensure that your GitHub Classroom group includes all members, and place all group members' names at the top of *all* submitted files (in appropriate JavaDoc commenting fashion) AND in the accompanying
readmefile.