secret
Created

  • Download Gist
gistfile1.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
 
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("");
}
 
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.