/**
* Fills the mutations array and sends to printMutations
* @param firstString original DNA generation.
*/
public static void mutation(String firstString)
{
final int ROWSINDEX = 26;
final int SPACEUSED = firstString.length();
char[][] mutations = new char[ROWSINDEX][SPACEUSED];
String dnaChars = "AGTC";
for (int i = 0; i < SPACEUSED; i++)
{
mutations[0][i] = firstString.charAt(i);
}
for (int i = 1; i < ROWSINDEX - 1; i++)
{
for (int j = 0; j < SPACEUSED; j++)
{
mutations[i][j] = mutations[i - 1][j];
}
int randomIndex = (int) (Math.random() * (SPACEUSED));
int randomChar = (int) (Math.random() * (dnaChars.length()));
mutations[i][randomIndex] = dnaChars.charAt(randomChar);
}
printMutations(mutations, ROWSINDEX, SPACEUSED);
}
/**
* Prints the 25 generations of mutations and the astrixes.
* @param mutations array that holds the mutated generations
* @param ROWSINDEX integer holding the max amount of rows possible
* @param SPACEUSED integer that holds the number of columns
*/
public static void printMutations(char[][] mutations, int ROWSINDEX, int SPACEUSED)
{
for (int i = 0; i < ROWSINDEX; i++)
{
for (int j = 0; j < SPACEUSED; j++)
{
System.out.print(" " + mutations[i][j]);
}
if (i > 0)
{
char[] a = mutations[i];
char[] a2 = mutations[i - 1];
if (Arrays.equals( a, a2 ) == true)
{
System.out.print("*");
}
}
System.out.println("");
}
}
}
出力の最後に、シミュレーション中に変更されなかった文字の列の下にアスタリスクを出力する必要があります。
プログラムの実行例は次のようになります。
$ java BeckJ0926
Enter a DNA sequence up to 80 bp: ATTCGGCTA
ATTCGGCTA
ATCCGGCTA
ATCCGTCTA
ATCCGTCTA *
...
ATCCGTCTT
AACCGTCTT
AATCGTCTT
* ** **
各列が変更されたかどうかを判断するためにブール配列を設定するのが最善かどうかはわかりません。これは私が最初にやろうとしていたことです。arrayLists を使用できません。