public class Quote { // the first card in null-terminated linked list private Card start; // helper linked-list data type private class Card { private String word; private Card next; public Card(String word) { this.word = word; this.next = null; } } // constructor - create an empty quote public Quote() { start = null; } // add the word w to the end of the quote public void addWord(String w) { Card newWord = new Card(w); // degenerate case when w is first word if (start == null) start = newWord; // otherwise, traverse list until card points to last word else { Card card = start; while(card.next != null) { card = _________________; } // add card for new word to end of list _________________ = newWord; } } // number of words in the quote public int count() { int total = 0; for (Card card = start; ___________________;__________________) total++; return total; } // return the ith word where i = 1 is first word in quote public String getWord(int i) { // check for less than i words in quote or invalid index if (count() < ___ || i <= 0) { throw new RuntimeException("index out of bounds"); } Card card = start; for (int count = 1; __________________; __________________) card = card.next; return ___________________________; } // insert w after the ith word, where i = 1 is the first word public void insertWord(int i, String w) { // check for less than i words in quote or invalid index ____________________________________________________________ ____________________________________________________________ ____________________________________________________________ Card newWord = new Card(w); Card card = start; for (int j = 1; j < i; j++) card = card.next; newWord.next = card.next; card.next = newWord; } // string representation of the quote public String toString(){ String s = ""; for (Card card = start; card != null; card = card.next) s = s + card.word + " "; return s; } public static void main(String[] args) { Quote q = new Quote(); q.addWord("A"); q.addWord(``rose''); q.addWord(``is''); q.addWord(``a''); q.addWord(``rose.''); System.out.println(q); System.out.println(q.count()); System.out.println(q.getWord(2)); q.insertWord(3, ``just''); System.out.println(q); System.out.println(q.count()); } }