And this is the interface: For this question, you are going to build a simple wo
ID: 3531251 • Letter: A
Question
And this is the interface:
For this question, you are going to build a simple word processor that takes input from the user (words), "remembers" them up, monitors for user command for undoing certain words, and monitors for user command for printing the scored words into a file. For the time being, we want to keep the program simple by taking the user out of the problem, so that your task is to build the core functionality of the word processor for this question only. Doing this will also facilitate testing. For the bonus part though, you can add the user back into the problem and make sure the rest of your code still works. You are given an interface WordProcessorInterface that specifies the methods needed for a basic word processor. Make sure you read the comments so you implement the methods according to the specifications. Implement this interface in a class called WordProcessor. The data structure you will implement to remember the words that a user types is called a StackQueue, which has both Stack and Queue functionality. To make this work, you must implement the data structure as a doubly-linked list, where each node stores a single word and the necessary pointers. In this way, each word that gets entered will be queued up by your word processor. Likewise, each undo will pop the most recently entered word. When the program is done, it will dequeue the structure and the words will show up in the correct order. To store a node, you will need to create a node class, with basic mutator, accessor and toString methods.Explanation / Answer
import java.util.LinkedList;
public class WordProcesor implements WordProcessorInterface {
private LinkedList<String> processor = new LinkedList<String>();
@Override
public boolean type(String word) {
return processor.add(word);
}
@Override
public boolean undo() {
String word = processor.removeLast();
if(word != null)
return true;
else
return false;
}
@Override
public String print() {
System.out.println("First Element: " + processor.getFirst());
return processor.getFirst();
}
@Override
public boolean empty() {
return processor.isEmpty();
}
}