So you should have an IntList.java file that looks something like:
Code:
public class IntList {
public IntList() { ... }
public void addToFront(int val) { ... }
public void addToEnd(int val) { ... }
public void removeFirst() { ... }
public void print() { ... }
}
In order to add a method to the class, you just need to add another method declaration. e.g.
Code:
public class IntList {
public IntList() { ... }
public void addToFront(int val) { ... }
public void addToEnd(int val) { ... }
public void removeFirst() { ... }
public void print() { ... }
public int length() { ... }
public String toString() { ... }
public void removeLast() { ... }
public void search(int input) { ... }
public void insertAt(int index, int newValue) { ... }
public void removeAt(int index) { ... }
}
I put "..." where the actual code for each method gets filled in. I'm not sure exactly what your IntListTest.java looks like. I would guess that it is a JUnit test class in which case it would look something like:
Code:
public class IntListTest extends TestCase {
public void testAddToFront() { ... }
public void testAddToEnd() { ... }
public void testRemoveFirst() { ... }
public void testPrint() { ... }
public int testLength() { ... }
public String testToString() { ... }
public void testRemoveLast() { ... }
public void testSearch() { ... }
public void testInsertAt() { ... }
public void testRemoveAt() { ... }
}
In this case you would fill in the "..." with code to test your functions and assert statements. For example a very simple test for the length() function might be:
Code:
public void testLength() {
IntList list = new IntList();
assertEquals("list should start as empty", list.length(), 0);
list.addToFront(2);
assertEquals("list with 1 element should have length of 1", list.length(), 1);
list.addToFront(1);
assertEquals("list with 2 elements should have length of 2", list.length(), 2);
}
This probably wouldn't be enough to throughly test the length() method but it's a start.
Hope this helps.
Bookmarks