In: Computer Science
please run it and show a sample. please dont change the methods.
public interface PositionalList extends Iterable {
/**
* Returns the number of elements in the list.
* @return number of elements in the list
*/
int size();
/**
* Tests whether the list is empty.
* @return true if the list is empty, false otherwise
*/
boolean isEmpty();
/**
* Returns the first Position in the list.
*
* @return the first Position in the list (or null, if empty)
*/
Position first();
/**
* Returns the last Position in the list.
*
* @return the last Position in the list (or null, if empty)
*/
Position last();
/**
* Returns the Position immediately before Position p.
* @param p a Position of the list
* @return the Position of the preceding element (or null, if p is
first)
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
Position before(Position p) throws IllegalArgumentException;
/**
* Returns the Position immediately after Position p.
* @param p a Position of the list
* @return the Position of the following element (or null, if p is
last)
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
Position after(Position p) throws IllegalArgumentException;
/**
* Inserts an element at the front of the list.
*
* @param e the new element
* @return the Position representing the location of the new
element
*/
Position addFirst(E e);
/**
* Inserts an element at the back of the list.
*
* @param e the new element
* @return the Position representing the location of the new
element
*/
Position addLast(E e);
/**
* Inserts an element immediately before the given Position.
*
* @param p the Position before which the insertion takes
place
* @param e the new element
* @return the Position representing the location of the new
element
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
Position addBefore(Position p, E e)
throws IllegalArgumentException;
/**
* Inserts an element immediately after the given Position.
*
* @param p the Position after which the insertion takes place
* @param e the new element
* @return the Position representing the location of the new
element
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
Position addAfter(Position p, E e)
throws IllegalArgumentException;
/**
* Replaces the element stored at the given Position and returns the
replaced element.
*
* @param p the Position of the element to be replaced
* @param e the new element
* @return the replaced element
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
E set(Position p, E e) throws IllegalArgumentException;
/**
* Removes the element stored at the given Position and returns
it.
* The given position is invalidated as a result.
*
* @param p the Position of the element to be removed
* @return the removed element
* @throws IllegalArgumentException if p is not a valid position for
this list
*/
E remove(Position p) throws IllegalArgumentException;
/**
* Returns an iterator of the elements stored in the list.
* @return iterator of the list's elements
*/
Iterator iterator();
/**
* Returns the positions of the list in iterable form from first to
last.
* @return iterable collection of the list's positions
*/
Iterable> positions();
}
import java.util.Iterator;
import Position; (interface)
import PositionalList;(interface)
public class DoublyLinkedList implements PositionalList
{
private int NumberofNode;
private Node head;
private Node tail;
public DoublyLinkedList()
{
head = new Node();
tail = new Node();
head.next =tail;
tail.prev = head;
}
@Override
public int size()
{
return NumberofNode;
return size;
}
@Override
public boolean isEmpty()
{
if(NumberofNode < 1 )
return
true;
else
return
false;
//return size ==0;
}
@Override
public Position first()
{
if(NumberofNode >=1)
return
head;
return null;
}
@Override
public Position last()
{
if(NumberofNode >= 1)
return
tail;
return null;
}
@Override
public Position before(Position p) throws
IllegalArgumentException
{
return null;
}
@Override
public Position after(Position p) throws
IllegalArgumentException {
// TODO Auto-generated method
stub
return null;
}
@Override
public Position addFirst(E e) {
// TODO Auto-generated method
stub
return null;
}
@Override
public Position addLast(E e) {
// TODO Auto-generated method
stub
return null;
}
@Override
public Position addBefore(Position p, E e)
throws
IllegalArgumentException {
// TODO Auto-generated method
stub
return null;
}
@Override
public Position addAfter(Position p, E e)
throws
IllegalArgumentException {
// TODO Auto-generated method
stub
return null;
}
@Override
public E set(Position p, E e) throws
IllegalArgumentException {
// TODO Auto-generated method
stub
return null;
}
@Override
public E remove(Position p) throws
IllegalArgumentException {
// TODO Auto-generated method
stub
return null;
}
@Override
public Iterator iterator() {
// TODO Auto-generated method
stub
return null;
}
@Override
public Iterable> positions() {
// TODO Auto-generated method
stub
return null;
}
public E removeFirst() throws IllegalArgumentException
{
// TODO Auto-generated method
stub
return null;
}
public E removeLast() throws IllegalArgumentException
{
// TODO Auto-generated method
stub
return null;
}
}
Well there are erros in the above code which are shown below, also Position.java is missing in the code given above. Kindly look into this.
Errors:-
javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/*
-d . Main.java PositionalList.java
Main.java:23: error: cannot find symbol
private Node head;
^
symbol: class Node
location: class DoublyLinkedList
Main.java:24: error: cannot find symbol
private Node tail;
^
symbol: class Node
location: class DoublyLinkedList
Main.java:52: error: cannot find symbol
public Position first()
^
symbol: class Position
location: class DoublyLinkedList
Main.java:60: error: cannot find symbol
public Position last()
^
symbol: class Position
location: class DoublyLinkedList
Main.java:68: error: cannot find symbol
public Position before(Position p) throws
IllegalArgumentException
^
symbol: class Position
location: class DoublyLinkedList
Main.java:68: error: cannot find symbol
public Position before(Position p) throws
IllegalArgumentException
^
symbol: class Position
location: class DoublyLinkedList
Main.java:75: error: cannot find symbol
public Position after(Position p) throws IllegalArgumentException
{
^
symbol: class Position
location: class DoublyLinkedList
Main.java:75: error: cannot find symbol
public Position after(Position p) throws IllegalArgumentException
{
^
symbol: class Position
location: class DoublyLinkedList
Main.java:81: error: cannot find symbol
public Position addFirst(E e) {
^
symbol: class E
location: class DoublyLinkedList
Main.java:81: error: cannot find symbol
public Position addFirst(E e) {
^
symbol: class Position
location: class DoublyLinkedList
Main.java:87: error: cannot find symbol
public Position addLast(E e) {
^
symbol: class E
location: class DoublyLinkedList
Main.java:87: error: cannot find symbol
public Position addLast(E e) {
^
symbol: class Position
location: class DoublyLinkedList
Main.java:93: error: cannot find symbol
public Position addBefore(Position p, E e)
^
symbol: class Position
location: class DoublyLinkedList
Main.java:93: error: cannot find symbol
public Position addBefore(Position p, E e)
^
symbol: class E
location: class DoublyLinkedList
Main.java:93: error: cannot find symbol
public Position addBefore(Position p, E e)
^
symbol: class Position
location: class DoublyLinkedList
Main.java:100: error: cannot find symbol
public Position addAfter(Position p, E e)
^
symbol: class Position
location: class DoublyLinkedList
Main.java:100: error: cannot find symbol
public Position addAfter(Position p, E e)
^
symbol: class E
location: class DoublyLinkedList
Main.java:100: error: cannot find symbol
public Position addAfter(Position p, E e)
^
symbol: class Position
location: class DoublyLinkedList
Main.java:107: error: cannot find symbol
public E set(Position p, E e) throws IllegalArgumentException
{
^
symbol: class Position
location: class DoublyLinkedList
Main.java:107: error: cannot find symbol
public E set(Position p, E e) throws IllegalArgumentException
{
^
symbol: class E
location: class DoublyLinkedList
Main.java:107: error: cannot find symbol
public E set(Position p, E e) throws IllegalArgumentException
{
^
symbol: class E
location: class DoublyLinkedList
Main.java:113: error: cannot find symbol
public E remove(Position p) throws IllegalArgumentException {
^
symbol: class Position
location: class DoublyLinkedList
Main.java:113: error: cannot find symbol
public E remove(Position p) throws IllegalArgumentException {
^
symbol: class E
location: class DoublyLinkedList
Main.java:130: error: cannot find symbol
public E removeFirst() throws IllegalArgumentException {
^
symbol: class E
location: class DoublyLinkedList
Main.java:135: error: cannot find symbol
public E removeLast() throws IllegalArgumentException {
^
symbol: class E
location: class DoublyLinkedList
PositionalList.java:21: error: cannot find symbol
Position first();
^
symbol: class Position
location: interface PositionalList
PositionalList.java:28: error: cannot find symbol
Position last();
^
symbol: class Position
location: interface PositionalList
PositionalList.java:36: error: cannot find symbol
Position before(Position p) throws IllegalArgumentException;
^
symbol: class Position
location: interface PositionalList
PositionalList.java:36: error: cannot find symbol
Position before(Position p) throws IllegalArgumentException;
^
symbol: class Position
location: interface PositionalList
PositionalList.java:44: error: cannot find symbol
Position after(Position p) throws IllegalArgumentException;
^
symbol: class Position
location: interface PositionalList
PositionalList.java:44: error: cannot find symbol
Position after(Position p) throws IllegalArgumentException;
^
symbol: class Position
location: interface PositionalList
PositionalList.java:52: error: cannot find symbol
Position addFirst(E e);
^
symbol: class E
location: interface PositionalList
PositionalList.java:52: error: cannot find symbol
Position addFirst(E e);
^
symbol: class Position
location: interface PositionalList
PositionalList.java:60: error: cannot find symbol
Position addLast(E e);
^
symbol: class E
location: interface PositionalList
PositionalList.java:60: error: cannot find symbol
Position addLast(E e);
^
symbol: class Position
location: interface PositionalList
PositionalList.java:70: error: cannot find symbol
Position addBefore(Position p, E e)
^
symbol: class Position
location: interface PositionalList
PositionalList.java:70: error: cannot find symbol
Position addBefore(Position p, E e)
^
symbol: class E
location: interface PositionalList
PositionalList.java:70: error: cannot find symbol
Position addBefore(Position p, E e)
^
symbol: class Position
location: interface PositionalList
PositionalList.java:81: error: cannot find symbol
Position addAfter(Position p, E e)
^
symbol: class Position
location: interface PositionalList
PositionalList.java:81: error: cannot find symbol
Position addAfter(Position p, E e)
^
symbol: class E
location: interface PositionalList
PositionalList.java:81: error: cannot find symbol
Position addAfter(Position p, E e)
^
symbol: class Position
location: interface PositionalList
PositionalList.java:92: error: cannot find symbol
E set(Position p, E e) throws IllegalArgumentException;
^
symbol: class Position
location: interface PositionalList
PositionalList.java:92: error: cannot find symbol
E set(Position p, E e) throws IllegalArgumentException;
^
symbol: class E
location: interface PositionalList
PositionalList.java:92: error: cannot find symbol
E set(Position p, E e) throws IllegalArgumentException;
^
symbol: class E
location: interface PositionalList
PositionalList.java:102: error: cannot find symbol
E remove(Position p) throws IllegalArgumentException;
^
symbol: class Position
location: interface PositionalList
PositionalList.java:102: error: cannot find symbol
E remove(Position p) throws IllegalArgumentException;
^
symbol: class E
location: interface PositionalList
Main.java:27: error: cannot find symbol
head = new Node();
^
symbol: class Node
location: class DoublyLinkedList
Main.java:28: error: cannot find symbol
tail = new Node();
^
symbol: class Node
location: class DoublyLinkedList
Main.java:38: error: cannot find symbol
return size;
^
symbol: variable size
location: class DoublyLinkedList
49 errors
OUTPUT:-