Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. You need to have the following .java files in the project: a. ListDriverClass b. ListInterface c. ListReferenceBased 2. Create a package with the name

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

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 the ListReferenceBased class.

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

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

public T remove(int givenPosition); /** Removes the entry at a given position from this list. Entries originally at positions higher than the given position are at the next lower position within the list, and the list's size is decreased by 1. 2 @param givenPosition An integer that indicates the position of the entry to be removed. @return A reference to the removed entry. @throws IndexOutOfBoundsException if either givenPosition < 1 or givenPosition > getLength(). */ public void removeAll(); /** Removes all entries from this list. */

public T get (int givenPosition); /** Retrieves the entry at a given position in this list. @param givenPosition An integer that indicates the position of the desired entry. @return A reference to the indicated entry. @throws IndexOutOfBoundsException if either givenPosition < 1 or givenPosition > getLength(). */

public int size(); /** Gets the length of this list. @return The integer 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 interface ListInterface.

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 are working properly. For example: Creating a list: LList myList = new LList(); 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 Node head = null;

private static class Node {

private int data;

private Node next;

}

public static void main(String[] args) {

ListReferenceBased based = new ListReferenceBased();

LinkedList myList = new LinkedList();

myList.add("15");

myList.add("25");

myList.add("35");

myList.add("45");

package ListBaseReference;

import ListInterface.ListIndexOutofBoundsException;

public interface ListInterface {

public void add(int newPosition, T newEntry) throws ListIndexOutOfBoundsException;

public T remove(int givenPosition) throws ListIndexOutOfBoundsException;

public void removeAll();

public T get(int givenPosition) throws ListIndexOutOfBoundsException;

public int size();

public boolean isEmpty();

}

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

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

}

}

}

package ListInterface;

import ListBaseReference.ListIndexOutOfBoundsException;

import ListBaseReference.ListInterface;

public class ListReferenceBased implements ListInterface {

private Node head;

private int numItems;

public ListReferenceBased() {

numItems = 0;

head = null;

}

private static class 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 void add(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(int givenPosition) throws ListIndexOutOfBoundsException {

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(int givenPosition) throws ListIndexOutOfBoundsException {

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;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

1. Think out loud as you solve problems.

Answered: 1 week ago

Question

=+What is your personal mission statement?

Answered: 1 week ago