Assignment class LinkedBag<E> implements Bag<E>

Collaboration: You may complete this assignment on your own with help from section leaders and Rick

Develop a generic (has <E>) collection class that implements the Bag ADT(copy and paste or download Bag.java) which is specified below as a Java interface. Use a type parameter such as <E> to allow for type-safe bags.

/**

* This interface specifies the methods for a Bag ADT. A bag is also known as a

* multi-set because bags are like a set with duplicate elements allowed.

* Order does not matter--how often an element exists does matter.

*

* This type is designed to begeneric so any type of element can be stored using

* the same implementation.

*/

publicinterface Bag<E> {

/**

* Add element to this Bag.

*

* @param element

* The element to insert.

*/

publicvoid add(E element);

/**

* Return true if no elements have been added to this bag.

*

* @return False if there is one or more elements in this bag.

*/

publicboolean isEmpty();

/**

* Return how many elements match el according to the equals method of the type

*

* @param el The element being searched for

*/

publicint occurencesOf(E el);

/**

* Remove any one element in this bag that equals element and return true.

* If el not "equals" an element in the Bag, return false.

*

* @param el The element being searched for

*/

publicboolean remove(E el);

}

Singly Linked Structure Required

You must use a singly linked data structure of Nodeobjects. Your class must begin like this:

/**

* YOUR NAME

*

* This class is one implementation of the Bag ADT. A bag is also known as a

* multi-set because bags are like a set with duplicate elements allowed.

* Order does not matter--how often an element exists does matter.

* You can add, remove, and count the occurrences of elements.

*

* This type is designed to be generic so any type of element can be stored using

* the same implementation.

*

*/

publicclass LinkedBag<E> implements Bag<E> {

privateclass Node {

private E data; // Reference to the element

private Node next; // null, or reference to next node

public Node(E element, Node nextRef) {

data = element;

next = nextRef;

}

}

// An external reference to the first element

private Node first;

// Create an empty Bag

public LinkedBag() {

first = null; // Explicitly assign null

}

// Add the other methods here

}

Grading Criteria 30pts

____/ +30 WebCat score for code and problem coverage

You may get 0 points if...

-30 If you did not use a singly linked structure of Node objects.