Advertisement
Guest User

Untitled

a guest
Jul 26th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. There are 2 occurrences of Rose!
  2. There are 1 occurrences of Daffodil!
  3.  
  4. There is a Rose!
  5. There is a Rose!
  6. There is a Daffodil!
  7.  
  8. public void find2(String searchName){
  9. Node theNode = firstNode;
  10. int occurrences = 0;
  11.  
  12. if(!isEmpty()){
  13. while (theNode.getItem().getName() != searchName){
  14. if (theNode.getItem().getName().equals(searchName)){
  15. occurrences++;
  16. }
  17. else if (theNode.getNext() == null){
  18. System.out.println("Flower not found!");
  19. return;
  20. }
  21.  
  22. theNode = theNode.getNext();
  23.  
  24. }
  25.  
  26. System.out.println("Found " + occurrences + " occurrences of " + searchName + ".");
  27. }
  28. }
  29.  
  30. else if (theNode.getNext() == null && occurrences == 0){
  31. System.out.println("Flower not found!");
  32. return null;
  33. }
  34.  
  35. Exception in thread "main" java.lang.NullPointerException
  36. at LinkedList.find2(LinkedList.java:69)
  37. at FinalProject.searchFlowers(FinalProject.java:81)
  38. at FinalProject.<init>(FinalProject.java:37)
  39. at FinalProject.main(FinalProject.java:10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement