All I needed to do was fix my getKey method. The changes below are what I did:
public int getKey(String s){
int [] arr=countLetters(s);
int maxDex=indexOfMax(arr);
int key;
if (maxDex<4) key= maxDex-4+26;
else key=maxDex-4;
return key;
}
solved Decryption method for two keys