Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package F28DA_CW1;
  2.  
  3. import java.util.Iterator;
  4. import java.util.LinkedList;
  5.  
  6. public class LListWords implements IWords {
  7.  
  8. private LinkedList<String> llist;
  9.  
  10. public LListWords() {
  11. llist = new LinkedList<String>();
  12. }
  13.  
  14. public void addWord(String word) throws WException {
  15.  
  16. if (wordExists(word) == false) {
  17. llist.add(word);
  18. } else {
  19. throw new WException("Word already present.");
  20. }
  21. }
  22.  
  23. public void delWord(String word) throws WException {
  24.  
  25. if(wordExists(word)==true) {
  26. llist.remove(word);
  27. }else {
  28. throw new WException("Word not present.");
  29. }
  30.  
  31. }
  32.  
  33. public boolean wordExists(String word) {
  34.  
  35. if (llist.contains(word) == true) {
  36. return true;
  37. } else {
  38.  
  39. return false;
  40. }
  41. }
  42.  
  43. public int nbWords() {
  44. return llist.size();
  45.  
  46. }
  47.  
  48. public Iterator<String> allWords() {
  49. return llist.iterator();
  50.  
  51. }
  52.  
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement