/**
* 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
* ** **
我不知道是否最好设置一个布尔数组来确定每一列是否发生了变化,这是我最初试图做的。我不能使用数组列表。