Skip to content

Instantly share code, notes, and snippets.

@Maslor
Last active August 29, 2015 14:26
Show Gist options
  • Save Maslor/4f3b8bf660b9c1b1f7df to your computer and use it in GitHub Desktop.
Save Maslor/4f3b8bf660b9c1b1f7df to your computer and use it in GitHub Desktop.
Receives an array of quotes and the name of the hero. Said hero will have one of its letters replaced by a number, which indicates which quote he says.
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class BatmanQuotes{
public static int indexOf(Pattern pattern, String s) {
Matcher matcher = pattern.matcher(s);
return matcher.find() ? matcher.start() : -1;
}
public static String getQuote(String[] quotes, String hero){
int n;
String returnString = "";
int index = indexOf(Pattern.compile("[(0-9)]"), hero);
if(index == hero.length()-1) n = Integer.parseInt(hero.substring(index));
else n = Integer.parseInt(hero.substring(index,index+1));
String[] split = hero.split("[(0-9)]");
if (indexOf(Pattern.compile("(Rob)"),split[0]) != -1) return returnString+="Robin: " + quotes[n];
else if (indexOf(Pattern.compile("(Bat)"),split[0]) != -1) return returnString+="Batman: " + quotes[n];
return returnString+="Joker: " + quotes[n];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment