Question: Design and write a complete test program to test if the MyLinkedList class in Listing 24.6 meets all requirements. Listing 1 public class MyLinkedList extends

Design and write a complete test program to test if the MyLinkedList class in Listing 24.6 meets all requirements.

Listing

1 public class MyLinkedList extends MyAbstractlist { private Node head, tail; /**

Create a default list */ public MyLinkedList() { /** Create a list

from an array of objects */ public MyLinkedList(E[] objects) { super (objects);

1 public class MyLinkedList extends MyAbstractlist { private Node head, tail; /** Create a default list */ public MyLinkedList() { /** Create a list from an array of objects */ public MyLinkedList(E[] objects) { super (objects); 10 11 { 12 13 /** Return the head element in the list */ public E getFirst() { if (size == 0) { return null; 14 15 16 17 18 else { return head.element; 19 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 /** Return the last element in the list */ public E getlast() { if (size == 0) { return null; else { return tail.element; /** Add an element to the beginning of the list */ public void addFirst(E e) { // Implemented in Section 24.4.3.1, so omitted here 36 37 38 /** Add an element to the end of the list */ public void addLast (E e) { // Implemented in Section 24.4.3.2, so omitted here 39 40 41 42 43 @0verride /** Add a new element at the specified index * in this list. The index of the head element is 0 */ public void add(int index, E e) { // Implemented in Section 24.4.3.3, so omitted here 44 45 46 47 { 48 49 /** Remove the head node and return the object that is contained in the removed node. */ public E removeFirst() { // Implemented in Section 24.4.3.4, so omitted here 50 51 52 53 54 55 /** Remove the last node and return the object that is contained in the removed node. */ public E removelast() { // Implemented in Section 24.4.3.5, so omitted here 56 57 58 59 60 61 @Override /** Remove the element at the specified position in this list. Return the element that was removed from the list. */ public E remove(int index) { // Implemented earlier in Section 24.4.3.6, so omitted here 62 63 64 65 66 67 @Override public String toString() { StringBuilder result = new StringBuilder("["); 68 69 70 71 Node current = head; for (int i = 0; i < size; i++) { result.append(current.element); current = current.next; if (current != null) { result.append(", "); // Separate two elements with a comma 72 73 74 75 76 77 else { result.append("]"); // Insert the closing ] in the string 78 79 80 81 82 83 return result.toString(); 84 85 86 87 @Override /** Clear the list */ public void clear() { size = 0; head = tail - null; 88 89 90 91 92 93 @Override /** Return true if this list contains the element e * / public boolean contains(E e) { System.out.print1n("Implementation left as an exercise"); 94 95 return true; 96 97 98 @Override /** Return the element at the specified index */ public E get(int index) { System.out.printIn("Implementation left as an exercise"); return null; 99 100 101 102 103 104 @Override /** Return the index of the head matching element * in this list. Return -1 if no match. */ public int index0f (E e) { System.out.printIn("Implementation left as an exercise"); return 0; 105 106 107 108 109 110 111 @Override /** Return the index of the last matching element in this list. Return -1 if no match. */ public int lastIndexOf(E e) { System.out.println("Implementation left as an exercise"); 112 113 114

Step by Step Solution

3.44 Rating (183 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Program Plan Create a MyLinkedListTestProgram class for the test of MyLinkedList class This MyLinkedList class extends MyAbstractList class which impl... View full answer

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 Java Programming Questions!