Question: How to implement the removeCurrent() method from the following class: public class BallSeq implements Cloneable { /** * A data class used for the linked

How to implement the removeCurrent() method from the following class:

public class BallSeq implements Cloneable { /** * A data class used for the linked structure for the linked list implementation of BallSeq. */ private static class Node { Ball data; Node next;

public Node(Ball data, Node next) { this.data = data; this.next = next; } }

private int manyNodes; private Node head; private Node precursor; // Remember that two of the fields are "model fields" // and will not be declared as real fields. // TODO: Define private getters for the two model fields (cursor and tail). private Node getTail() { if (head == null) { return null; } else { Node current = head; while (current.next != null) { current = current.next; } return current; } } private Node getCursor() { if (precursor == null) { return head; } return precursor.next; }

/** * Remove the current element from this sequence. * @param - none * @precondition * isCurrent() returns true. * @postcondition * The current element has been removed from this sequence, and the * following element (if there is one) is now the new current element. * If there was no following element, then there is now no current * element. * @exception IllegalStateException * Indicates that there is no current element, so * removeCurrent may not be called. **/ public void removeCurrent( ) { assert wellFormed() : "invariant wrong at start of removeCurrent()"; assert wellFormed() : "invariant wrong at end of removeCurrent()"; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!