Question: Using the two following methods; findFrequency and hasMutation; how do I write a method countTotalMutations(String[] seqArray) that counts the number of mutated DNA sequences that
Using the two following methods; findFrequency and hasMutation; how do I write a method countTotalMutations(String[] seqArray) that counts the number of mutated DNA sequences that occur within an array.
-
This must be done by building on the technique for findFrequency and adding calls to hasMutation.
-
Parameters:
seqArray - An array of DNA sequences
Returns:
The number of mutated DNA sequences found within the array.
Note that DNA sequences contain two to four of the following characters: {A,C,G,T} in any order. A mutated sequence contains adjacent repeated characters , so ACCG, TTCCA, and AACC are all mutated sequences.
-
public static int findFrequency(String target, String[] strings) {
int maxFrequency = 0;
for ( String DNACode : strings ) {
if ( DNACode.equals(target) ) {
maxFrequency = maxFrequency + 1;
}
}
return maxFrequency;
}
public static boolean hasMutation(String DNACode) {
for ( int i = 0 ; i < DNACode.length() ; i++ ) {
for ( int j = i + 1 ; j < DNACode.length() ; j++ ) {
if ( DNACode.charAt(i) == DNACode.charAt(j) ) {
return true;
}
}
}
return false;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
