import java.util.*; //for the LinkedList /** * Class representing a command for a Turtle * @author Dawn Finney **/ public class TurtleCommand{ /**The type of the command such as world, moveTo, forward, etc**/ public String type; /**The parameters for the command**/ public LinkedList parameters; /** * Constructor taking in a the type of the command * @param type the command type **/ public TurtleCommand(String type){ this.type = type; parameters = new LinkedList(); } /** * Accessor to return type * @return the command type **/ public String getType(){ return type; } /** * Accessor to return the LinkedList of parameters * @return the LinkedList of parameters **/ public LinkedList getParameters(){ return parameters; } /** * Method to return an integer from specific index from the LinkedList of parameters * @return an integer from specific index from the LinkedList of parameters **/ public Integer getParameter(int i){ return parameters.get(i); } /** * Method to add to the LinkedList of parameters * @param parameter the item to the LinkedList of parameters **/ public void addParameter(int parameter){ parameters.add(parameter); } /** * Method to return a String representation of the command * @return a String representation of the command **/ public String toString(){ //if the parameter list is not empty and the command type is not null if (!parameters.isEmpty() && type != null){ //initize ret to the command type plus a space String ret = type + " "; //loop through the parameters LinkedList list for (int i = 0; i < parameters.size(); i++){ //append the parameter to the String ret ret = ret + parameters.get(i) + " "; } //return the String representation return ret; } //return null if the parameter list is empty or the command type is null return null; } }