Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. //COMANDO CHOOSE CARD //
  2.  
  3. public class ChooseCardCommand extends Command{
  4.         public ChooseCardCommand(String command) {
  5.                 super(command);
  6.         }
  7.  
  8.         @Override
  9.     //Se espera un comando de este tipo "CHOOSE OPCION_1,OPCION_2,....,OPCION_N
  10.         public String execute() {
  11.         String res = "Introduce alguno de estos comandos:\n";
  12.         String [] parts = command.split(" ");
  13.         if(parts.length != 2)
  14.             res = "El comando recibido es invalido";
  15.         else{
  16.             //La segunda parte son las opciones separadas por comas
  17.             String[] opciones = parts[1].split(",");
  18.  
  19.             //Recorremos todas las opciones
  20.             for(int i=0 ; i<opciones.length ; i++)
  21.                 res += "\t* " + opciones[i] + "\n";
  22.         }
  23.         return res;
  24.         }
  25. }
  26.  
  27. //COMANDO INFO //
  28. public class InfoCommand extends Command {
  29.         public InfoCommand(String command) {
  30.                 super(command);
  31.         }
  32.  
  33.         @Override
  34.         public String execute() {
  35.                 String res = null;
  36.                 String [] parts = command.split(".",2);
  37.                 if(parts.length == 2){
  38.                        res=parts[1];
  39.                 }
  40.         else{
  41.             res = "El comando recibido es invalido"
  42.         }
  43.  
  44.                 return res;
  45.         }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement