Question: please do not copy from old questions this third time i am posting the question when i call the method it will keep betwen the
please do not copy from old questions this third time i am posting the question
when i call the method it will keep betwen the l indexes that i pass and remove the rest.
public class MyList
public MyList() { elements = (G[]) new Object[10]; }
public MyList(int size) { elements = (G[]) new Object[size]; }
public int size() { return counter; }
public int length() { return elements.length; }
public void display() { for(G element: elements) System.out.println(element); }
public boolean isEmpty() { if(counter == 0) return true; else return false; }
public void add(G element) { if(counter
elements = temp; elements[counter++] = element; } }
public void clear() { for(int index = 0 ; index
}
public void set(int index, G element) { if(index = counter) System.out.println("Index is out of the range."); else elements[index] = element; }
public boolean contains(G element) { for(G instance : elements) if(element.equals(instance)) //(element == instance)) return true;
return false; }
public int indexOf(G element) { for(int index = 0 ; index
return -1; }
public G[] toArray() { G temp[] = (G[]) new Object[counter]; for(int index = 0 ; index
return temp; }
public G remove(int index) { if(index = counter) { System.out.println("Index is out of the range."); return null; } else { G temp = elements[index]; for(int secIndex = index ; secIndex
elements[counter-1] = null; counter--; return temp; } } }
public class Test { public static void main(String args[]) { MyList
x.add(1); x.add(2); x.add(3); x.add(4); x.add(5); x.add(6); x.add(7); x.keepBetween(2, 5); x.display(); }
}
Download the project, import it on Eclipse, and implement the following method in the class MyList.java: public T[] keepBetween(int from Index, int toIndex) For Example: content index ==> Obj. 01 0 Obj. 02 1 Obj. 03 2 Obj. 04 3 Obj. 05 4 Obj. 06 5 Obj. 07 6 7 8 9 Where Obj. 01, Obj. 02, Obj. 03, etc.... stand for Object01, Object02, Object03, etc.... After calling the method: keepBetween(2, 5) the output will be: content Obj. 04 Obj. 06 Obj. 03 0 Obj. 05 2 index ==> 1 3 4 5 6 7 8 9 Test your method in the Test.java class and display the output in the console output tab
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
