Question: i need help to fix the code in bold as i am trying to make my remove method remove a specific elemnt but for some

i need help to fix the code in bold as i am trying to make my remove method remove a specific elemnt but for some reason i can't get it right so please help me correct it and tellme how i did wrong thank you and so long as you can make the test work with the method without changing the plus i'll be glad

thank you

the class that contains the remove method i wanna fix

package test2; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.Iterator; import java.util.ListIterator; import java.util.NoSuchElementException;

import javafx.scene.Node;

public class testing { protected Node head; protected Node tail; protected int size; private T[] data;//Array in which the elements in this list are stored. private ArrayList list; public Iteratoriterator;

public testing() { size =0; } /** * this class keeps track of each element information * @author * */ class Node { private T data; private Node next; private Node prev; Node (T data, Node next,Node prev) { this.setData(data); this.setNext(next); this.setPrev(prev); } public T getData() {return data;} public void setData(T data) {this.data = data;} public Node getNext() {return next;} public void setNext(Node next) {this.next = next; } public Node getPrev() {return prev; } public void setPrev(Node prev) {this.prev = prev;} } public testing addToEnd(T data) { Node newNode = new Node(data, null, getTail()); if(getTail()!=null) {getTail().setNext(newNode);} setTail(newNode); if(getHead()==null) { setHead(newNode); } size++; System.out.println(data); return this;} public testing addToFront(T data) { Node newNode = new Node(data, getHead(), getTail()); if(getHead()!=null) {getHead().setPrev(newNode);} if(getTail()==null) { setTail(newNode); } setHead(newNode); size++; System.out.println(data);

return this;} public T getFirst() { if(getHead()!=null) return getHead().data; else return null;} public T getLast() { if(getTail()!=null) return getTail().data;

else return null; }

public void remove(String string, Comparator comparator) {

Node previous = getTail(); Node current = getHead(); while (current != null) { if(current.getData().equals(comparator)) { current = current.next; if(previous == null) { previous = current; size--; } else { previous.next = current; size--; } } else { previous = current; current = current.next; } } size--; }

public Node getHead() { return head; }

public void setHead(Node head) { this.head = head; }

public Node getTail() { return tail; }

public void setTail(Node tail) { this.tail = tail; }}

its test

package test2;

import static org.junit.Assert.*;

import java.util.ArrayList; import java.util.Comparator; import java.util.Iterator; import java.util.ListIterator; import java.util.NoSuchElementException;

import org.junit.After; import org.junit.Before; import org.junit.Test;

public class testingTest { testing linkedString; testing linkedDouble; StringComparator comparator; DoubleComparator comparatorD;

@Before public void setUp() throws Exception { linkedString = new testing(); linkedString.addToEnd("Hello"); linkedString.addToEnd("World"); comparator = new StringComparator(); //STUDENT: Use the linkedDouble for the STUDENT tests linkedDouble = new testing(); linkedDouble.addToEnd(15.0); linkedDouble.addToEnd(100.0); comparatorD = new DoubleComparator(); }

@After public void tearDown() throws Exception { linkedString = null; comparator = null; }

@Test public void testAddToEnd() { assertEquals("World", linkedString.getLast()); linkedString.addToEnd("End"); assertEquals("End", linkedString.getLast()); }

@Test public void testAddToEndSTUDENT(){ //test addToEnd for the linkedDouble assertEquals("World", linkedString.getLast()); linkedString.addToEnd("End"); assertEquals("End", linkedString.getLast()); } @Test public void testAddToFront() { assertEquals("Hello", linkedString.getFirst()); linkedString.addToFront("Begin"); assertEquals("Begin", linkedString.getFirst()); }

@Test public void testAddToFrontSTUDENT(){ //test addToFront for the linkedDouble assertEquals("Hello", linkedString.getFirst()); linkedString.addToFront("Begin"); assertEquals("Begin", linkedString.getFirst()); }

@Test public void testRemove() { // remove the first assertEquals("Hello", linkedString.getFirst()); assertEquals("World", linkedString.getLast()); linkedString.addToFront("New"); assertEquals("New", linkedString.getFirst()); linkedString.remove("New", comparator); assertEquals("Hello", linkedString.getFirst()); //remove from the end of the list linkedString.addToEnd("End"); assertEquals("End", linkedString.getLast()); linkedString.remove("End", comparator); assertEquals("World", linkedString.getLast()); //remove from middle of list linkedString.addToFront("Begin"); assertEquals("Begin", linkedString.getFirst()); assertEquals("World", linkedString.getLast()); linkedString.remove("Hello", comparator); assertEquals("Begin", linkedString.getFirst()); assertEquals("World", linkedString.getLast()); } private class StringComparator implements Comparator {

@Override public int compare(String arg0, String arg1) { // TODO Auto-generated method stub return arg0.compareTo(arg1); } } private class DoubleComparator implements Comparator {

@Override public int compare(Double arg0, Double arg1) { // TODO Auto-generated method stub return arg0.compareTo(arg1); } } }

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!