Question: public class ProjectBTester { public static void main(String[] args) { HeadTailListInterface list = new ArrayHeadTailList (10); // comment the line above and un-comment the line

public class ProjectBTester {

public static void main(String[] args) {

HeadTailListInterface list = new ArrayHeadTailList(10);

// comment the line above and un-comment the line below to test the extra credit

// NOTE: for the extra credit, all lines should match except for the capacity print out-

// the capacity of an ArrayList is private, so this cannot be shown

// HeadTailListInterface list = new ListHeadTailList(10);

System.out.println("********TESTING ISEMPTY AND EMPTY DISPLAY");

System.out.println("Empty is true: " + list.isEmpty());

System.out.println();

System.out.println("Should display: 0 elements; capacity = 10");

list.display();

System.out.println();

System.out.println(" ********TESTING ADD TO FRONT");

// test addFront to emtpy

list.addFront(2);

System.out.println("Should display: 1 elements; capacity = 10 [2]");

list.display();

System.out.println();

// test addFront to not empty

list.addFront(4);

list.addFront(3);

System.out.println("Should display: 3 elements; capacity = 10 [3, 4, 2]");

list.display();

System.out.println();

System.out.println("Empty is false: " + list.isEmpty());

System.out.println(" ********TESTING CLEAR");

list.clear();

System.out.println("Should display: 0 elements; capacity = 10");

list.display();

System.out.println(" ********TESTING ADD TO BACK");

// test addBack to empty

list.addBack(7);

System.out.println("Should display: 1 elements; capacity = 10 [7]");

list.display();

System.out.println();

// test addBack to non empty

list.addBack(10);

list.addBack(5);

System.out.println("Should display: 3 elements; capacity = 10 [7, 10, 5]");

list.display();

System.out.println(" ********TESTING CONTAINS");

System.out.println("Contains 5 true:"+list.contains(5));

System.out.println("Contains 7 true:"+list.contains(7));

System.out.println("Contains 4 false: "+list.contains(4));

System.out.println(" ********TESTING ADD WITH EXPANSION");

list.clear();

for(int i=0; i<32; i++) {

list.addBack(i);

}

System.out.println("Should display: 32 elements; capacity = 40 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]");

list.display();

System.out.println(" ********TESTING INDEX OF");

System.out.println("Index of 0is0: " + list.indexOf(0));

System.out.println("Index of 31 is 31: " + list.indexOf(31));

System.out.println("Index of -5 is -1: " + list.indexOf(-5));

System.out.println("Index of 32 is -1: " + list.indexOf(32));

list.addFront(3);

list.addBack(5);

System.out.println("Index of 3is0: " + list.indexOf(3));

System.out.println("Index of 5is6: " + list.indexOf(5));

System.out.println(" ********TESTING LAST INDEX OF");

System.out.println("Last index of 0is1:" + list.lastIndexOf(0));

System.out.println("Last index of 31 is 32: " + list.lastIndexOf(31));

System.out.println("Last index of -5 is -1: " + list.lastIndexOf(-5));

System.out.println("Last index of 35 is -1: " + list.lastIndexOf(35));

System.out.println("Last index of 3is4:" + list.lastIndexOf(3));

System.out.println("Last index of 5is 33: " + list.lastIndexOf(5));

System.out.println(" ********TESTING SIZE");

System.out.println("Size is 34: " + list.size());

System.out.println();

System.out.println(" ********TESTING GET ENTRY");

System.out.println("Element in position 15 is 14: "+list.getEntry(15));

System.out.println("Element in position0 is3: "+list.getEntry(0));

System.out.println("Element in position 39 is null: "+list.getEntry(39));

System.out.println("Element in position -1 is null: "+list.getEntry(-1));

System.out.println(" ********TESTING REMOVES");

// test removes from nonEmpty

System.out.println("Remove front element 3: "+list.removeFront());

System.out.println("Remove back element5 :"+list.removeBack());

System.out.println("Remove front element 0: "+list.removeFront());

System.out.println("Remove back element 31: "+list.removeBack());

System.out.println();

System.out.println("Should display: 30 elements; capacity = 40 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]");

list.display();

System.out.println();

// test removes from empty

list.clear();

System.out.println("Remove element null: "+list.removeFront());

System.out.println("Remove element null: "+list.removeBack());

System.out.println();

// test removes from singleton

list.clear();

list.addFront(1);

System.out.println("Remove element 1: "+list.removeFront());

System.out.println("Should display: 0 elements; capacity = 40");

list.display();

System.out.println();

System.out.println();

list.addBack(1);

System.out.println("Remove element 1: "+list.removeFront());

System.out.println("Should display: 0 elements; capacity = 40");

list.display();

System.out.println();

System.out.println();

list.addFront(1);

System.out.println("Remove element 1: "+list.removeBack());

System.out.println("Should display: 0 elements; capacity = 40");

list.display();

System.out.println();

System.out.println();

list.addBack(1);

System.out.println("Remove element 1: "+list.removeBack());

System.out.println("Should display: 0 elements; capacity = 40");

list.display();

System.out.println();

System.out.println();

System.out.println(" ********TESTING MIX OF ADDS AND REMOVES");

list.addFront(3);

list.addBack(2);

list.addFront(4);

list.addFront(5);

list.addBack(3);

list.addBack(8);

list.addBack(9);

System.out.println("Should display: 7 elements; capacity = 40 [5, 4, 3, 2, 3, 8, 9]");

list.display();

System.out.println();

list.removeFront();

list.removeBack();

System.out.println("Should display: 5 elements; capacity = 40 [4, 3, 2, 3, 8]");

list.display();

System.out.println();

System.out.println("********TESTING WITH STRINGS");

HeadTailListInterface wordList = new ArrayHeadTailList(5);

wordList.addFront("job!");

wordList.addFront("Nice");

wordList.addFront("it!");

wordList.addFront("did");

wordList.addFront("You");

System.out.println("Should display: 5 elements; capacity = 5 [You, did, it!, Nice, job!]");

wordList.display();

System.out.println();

System.out.println("Contains \"Nice\" is true: "+ wordList.contains(new String("Nice")));

System.out.println("Contains \"You\"is true: "+ wordList.contains(new String("You")));

System.out.println("Contains \"you\"is false: "+ wordList.contains(new String("you")));

System.out.println();

System.out.println("Index of \"it!\" is 2: "+ wordList.indexOf(new String("it!")));

System.out.println("Last index of \"it!\" is 2: "+ wordList.lastIndexOf(new String("it!")));

}

}

-----------------------------------------------------------------------------------------------------------

public class ArrayHeadTailList implements HeadTailListInterface {

private T[] listArray;

private int numberOfElements;

private static final int DEFAULT_CAPACITY = 10;

/**

* Displays the contents of the list to the console, in order.

*/

public void display() {

System.out.print(numberOfElements+ " elements; capacity = "+ DEFAULT_CAPACITY +" ");

for(int i = 0; i < numberOfElements; i++) {

System.out.print(listArray[i] +" ");

}

}

/**

* Determines the position in the list of a given entry.

* If the entry appears more than once, the first index is returned.

*

* @param anEntry the object to search for in the list.

* @return the first position the entry that was found or -1 if the object is not found.

*/

public int indexOf(T anEntry) {

return 0;

}

/**

* Determines the position in the list of a given entry.

* If the entry appears more than once, the last index is returned.

*

* @param anEntry the object to search for in the list.

* @return the last position the entry that was found or -1 if the object is not found.

*/

public int lastIndexOf(T anEntry) {

return 0;

}

/**

* Determines whether an entry is in the list.

*

* @param anEntry the object to search for in the list.

* @return true if the list contains the entry, false otherwise

*/

public boolean contains(T anEntry) {

return false;

}

/**

* Gets the length of this list.

*

* @return The integer number of entries currently in the list.

*/

public int size() {

return numberOfElements;

}

/**

* Checks whether this list is empty.

*

* @return True if the list is empty, or false if the list contains one or more elements.

*/

public boolean isEmpty() {

return numberOfElements > 0;

}

}

----------------------------------------------------------------------------------------------------

Help me with the Java programing:

Please provide all the methods in the ArrayHeadTailList

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!