Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package F28DA_CW1;
- import java.util.Iterator;
- import java.util.LinkedList;
- public class LListWords implements IWords {
- private LinkedList<String> llist;
- public LListWords() {
- llist = new LinkedList<String>();
- }
- public void addWord(String word) throws WException {
- if (wordExists(word) == false) {
- llist.add(word);
- } else {
- throw new WException("Word already present.");
- }
- }
- public void delWord(String word) throws WException {
- if(wordExists(word)==true) {
- llist.remove(word);
- }else {
- throw new WException("Word not present.");
- }
- }
- public boolean wordExists(String word) {
- if (llist.contains(word) == true) {
- return true;
- } else {
- return false;
- }
- }
- public int nbWords() {
- return llist.size();
- }
- public Iterator<String> allWords() {
- return llist.iterator();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement