I don't exactly know what you want and we could use a little more explanation, but I'm guessing your code would be something like:
if (rotor.equals("Slow")) {
resultAfterRotor = Character.toString((slowRotor.charAt(position)));
} else if (rotor.equals("Medium")) {
resultAfterRotor = // ... something else
} else if (rotor.equals("Fast")) {
resultAfterRotor = // ... something else
}
// ...
Instead you could use a switch statement which avoids doing a comparison for each case as you would with if-else-if-else-if. (for few cases though (~3 maybe), switch will compile to if-else bytecode since I guess that's fastest):
private final static String slowRotor = "EKMFLGDQVZNTOWYHXUSPAIBRCJ";
private final static String mediumRotor = "...";
private final static String fastRotor = "...";
public static void main(String[] args){
String rotor = GUI.getRotorInPosition("slow");
int position = (alphabet.indexOf(result));
String resultAfterRotor = getResultAfterRotor(rotor);
// ...
}
private String getResultAfterRotor(String rotor) {
switch(rotor){
case "Slow": {
return Character.toString(slowRotor.charAt(position));
}
case "Medium": {
return Character.toString(mediumRotor.charAt(position));
}
case "Fast": {
return Character.toString(fastRotor.charAt(position));
}
}
}
Or you could use a Map
private static final Map<String, String> rotorMap = new HashMap<>();
static {
rotorMap.put("Slow", "EKMFLGDQVZNTOWYHXUSPAIBRCJ");
rotorMap.put("Slow2", "...");
rotorMap.put("Slow3", "...");
}
public static void main(String[] args){
String slowRotor = GUI.getRotorInPosition("slow");
int position = (alphabet.indexOf(result));
String resultAfterRotor = Character.toString(rotorMap.get(slowRotor).charAt(position));
// ...
}