This is the only part of my assignment that has problem.
Can anyone tell me what's wrong?
I debug it, it shows me NullPointerException...
please give me a hint, i urgently need this to be done.
Its due today.
So, I am supposed to write a method captured that will re-arrange my original list.
This method records the capture of the person with the given name, transferring the person from the play ring to the captured list. This operation should not change the play ring order of printPlayRing (i.e., whoever used to be printed first should still be printed first unless that’s the person who was caputred, in which case the person who used to be printed second should now be printed first). Throw an IllegalArgumentException if the given name is not part of the current play ring and throw an IllegalStateException if the game is over (it doesn’t matter which it throws if both are true). Ignore case in comparing names
public void capture(String name){
Node current = front;
// if player's name is not in the list, throw new IllegalArgumentException
if(playRingContains(name) != true){
throw new IllegalArgumentException();
}
// if game is over, throw IllegalStateException
if(gameOver() == true){
throw new IllegalStateException();
}
// Go through the list when game is not over and ring contains the player name
while(playRingContains(name) && !gameOver()){
if(current.item.equals(name)){
Node temp = current;
Node helper = current;
helper.next = null;
if(captured == null){
captured = helper;
}else{
captured.next = helper;
captured = captured.next;
}
if(current.prev == null){
Node previous = current;
while(previous.next != null){
previous = previous.next;
}
captured.prevItem = previous.item;
temp = temp.next;
previous.setGold(captured.gold);
}
if(current != null && current.prev != null){
if(current.next == null){
temp.prev.next = null;
}
temp.prev.next = temp.next;
temp.prev.setGold(captured.gold);
}
}
}
current = current.next;
}
I know roughly what I am supposed to do.
1. Store the node to the new list.
2. Delete the node from the old list by making the previous node in the list pointing to the next list.
3. If the new list is empty, just store the node. If the new list is not empty, store the node to the next of the list.