I'm trying to let the voter search their account details by using their student id only, so how should I pass into the search method??
SearchMethod:
public T search(T data) {
Node currentNode = getNode(data);
if (currentNode != null) {
return currentNode.data;
} else {
return null;
}
}
private Node getNode(T data) {
Node currentNode = this.firstNode;
while (currentNode != null) {
if (currentNode.data.equals(data)) {
return currentNode;
}
currentNode = currentNode.next;
}
return currentNode;
}
Driver Program:
List<Voter> voterList = new DoublyLinkedList<>();
//Username, password, StudID
voterList.add(new Voter("Alice", "password1", "001"));
voterList.add(new Voter("Bob", "password2", "002"));
voterList.add(new Voter("Charlie", "password3", "003"));
String valueSearch = "003";
System.out.println(voterList.search(new Voter("", "", valueSearch)));
I expect that it would come out all the details of the voter based on the studentId they inputed but why it cannot QQ.