Skip to content

Instantly share code, notes, and snippets.

Created February 2, 2013 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/327492515289d66308d1 to your computer and use it in GitHub Desktop.
Save anonymous/327492515289d66308d1 to your computer and use it in GitHub Desktop.
public class Command {
static final int CMD_LET = 0;
static final int CMD_DOC = 1;
static final int CMD_PRINT = 2;
static final int CMD_DO = 3;
static final int CMD_HISTORY = 4;
static final int CMD_END = 5;
static final int INVALID = 6;
String s;
String b;
public Command(String s){
this.s = s;
b = s.toLowerCase();
}
public int getCommand(){
if(b.substring(0,3) == "let")
return(CMD_LET);
if(b.substring(0,3) == "doc" && b.substring(0,2) != "do")
return(CMD_DOC);
if(b.substring(0,5) == "print")
return(CMD_PRINT);
if(b.substring(0,2) == "do")
return(CMD_DO);
if(b.substring(0,7) == "history")
return(CMD_HISTORY);
if(b.substring(0,3) == "end")
return(CMD_END);
else{ return(INVALID);
}
}
public String getArg(){
if(getCommand() == 0)
return(s.substring(4));
if(getCommand() == 1)
return(s.substring(4));
if(getCommand() == 2)
return(s.substring(6));
if(getCommand() == 3)
return(s.substring(3));
if(getCommand() == 4)
return(s.substring(8));
if(getCommand() == 5)
return(s.substring(4));
if(getCommand() == 6)
return("");
else{ return("");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment