Menu

(Solved) : 1 Need Following Java Files Project Listdriverclass B Listinterface C Listreferencebased Q34522997 . . .

1. You need to have the following .java files in theproject:

a. ListDriverClass

b. ListInterface

c. ListReferenceBased

2. Create a package with the name of ListDriverClass

a. Your ListDriverClass contains method main().

b. Your ListDriverClass needs to try different methods in theListReferenceBased class.

3. Add an interface with the name of ListInterface to thepackage. Your interface contains the following methods’headers:

public void add(int newPosition, T newEntry); /** Adds a newentry at a specified position within this list. Entries originallyat and above the specified position are at the next higher positionwithin the list. The list’s size is increased by 1. @paramnewPosition An integer that specifies the desired position of thenew entry. @param newEntry The object to be added as a new entry.@throws IndexOutOfBoundsException if either newPosition < 1 ornewPosition > getLength() + 1. */

public T remove(int givenPosition); /** Removes the entry at agiven position from this list. Entries originally at positionshigher than the given position are at the next lower positionwithin the list, and the list’s size is decreased by 1. 2 @paramgivenPosition An integer that indicates the position of the entryto be removed. @return A reference to the removed entry. @throwsIndexOutOfBoundsException if either givenPosition < 1 orgivenPosition > getLength(). */ public void removeAll(); /**Removes all entries from this list. */

public T get (int givenPosition); /** Retrieves the entry at agiven position in this list. @param givenPosition An integer thatindicates the position of the desired entry. @return A reference tothe indicated entry. @throws IndexOutOfBoundsException if eithergivenPosition < 1 or givenPosition > getLength(). */

public int size(); /** Gets the length of this list. @return Theinteger number of entries currently in the list. */

public boolean isEmpty(); /** Sees whether this list is empty.@return True if the list is empty, or false if not. */

4. Add a class ListReferenceBased to the package.

ListReferenceBased class implements the interfaceListInterface.

5. In the main(): a. Create a list with the name of myList b.Try all the methods from LList in the main to make sure they areworking properly. For example: Creating a list: LList myList = newLList(); Trying the add method: myList.add(“15”); myList.add(“25”);myList.add(“35”); myList.add(“45”);

import java.util.*;

import ListInterface.ListReferenceBased;

public class ListDriverClass{

private static Nodehead = null;

private staticclass Node {

private int data;

private Node next;

}

public staticvoid main(String[] args) {

ListReferenceBased based = newListReferenceBased();

LinkedList<String> myList = newLinkedList<String>();

myList.add(“15”);

myList.add(“25”);

myList.add(“35”);

myList.add(“45”);

package ListBaseReference;

importListInterface.ListIndexOutofBoundsException;

public interfaceListInterface<T> {

public voidadd(int newPosition, T newEntry)throws ListIndexOutOfBoundsException;

public T remove(intgivenPosition) throwsListIndexOutOfBoundsException;

public void removeAll();

public T get(intgivenPosition) throwsListIndexOutOfBoundsException;

public int size();

public boolean isEmpty();

}

for (int i = 0; i <myList.size(); i++) {

System.out.println(myList.get(i));

}

}

}

package ListInterface;

importListBaseReference.ListIndexOutOfBoundsException;

import ListBaseReference.ListInterface;

public classListReferenceBased<T> implementsListInterface {

private Node head;

private int numItems;

public ListReferenceBased() {

numItems = 0;

head = null;

}

private staticclass Node {

public Node(Object item, Node head) {

}

private Node next;

public Object item;

}

private Node find(int index){

Node curr = head;

for (int skip = 0; skip <index; skip++) {

curr = curr.next;

}

return curr;

}

public voidadd(int newPosition, Object newEntry)throws ListIndexOutOfBoundsException {

if (newPosition >= 0 && newPosition< numItems + 1) {

}

if (newPosition == 0) {

Object item = null;

Node newNode = new Node(item, head);

}

}

public Object remove(intgivenPosition) throwsListIndexOutOfBoundsException {

if (givenPosition >= 0 &&givenPosition < numItems ) {

if (givenPosition == 0) {

head = head.next;

} else {

int index = (Integer)null;

Node prev = find(index – 1);

Node curr = prev.next;

prev.next = curr.next;

}

numItems–;

} else {

}

return givenPosition;

}

public void removeAll() {

head = null;

numItems = 0;

}

public Object get(intgivenPosition) throwsListIndexOutOfBoundsException {

if (givenPosition >= 0 &&givenPosition < numItems) {

Node curr = find(givenPosition);

Object data = curr.item;

}

Object dataItem = null;

return dataItem;

}

public int size() {

return numItems;

}

public boolean isEmpty() {

return numItems == 0;

}

}

Expert Answer


Answer to 1 Need Following Java Files Project Listdriverclass B Listinterface C Listreferencebased Q34522997 . . .

OR