First of all, there is no declaration of a char named variable in the aGoodBase method you are checking in the if statement.
And secondly, and this is the real deal, such variable could never exist since char is a reserved keyword in Java (like byte, int, long, public, strictfp etc.) , and it can be used only to declare a variable as a primitive char type.
This answers why DnaTest is not compiling.
Now, let's consider a possible solution for your answer:
public class DnaTest {
private final static char [] baseArray = {'A', 'C', 'G', 'T'};
// checks whether String s only contains the right base elements or not
public static boolean aGoodBase(String s){
String s1 = s.toUpperCase(); // just ensuring case insensitive checks
for (int i=0; i<s1.length(); i++) {
char check = s1.charAt(i);
if (baseArray[0] != check &&
baseArray[1] != check &&
baseArray[2] != check &&
baseArray[3] != check) {
// at least one char of s is not in baseArray
return false;
}
}
return true;
}
public static void main(String[] args) {
// should be true
System.out.println("Does GATTACA have aGoodBase? " + aGoodBase("GATTACA"));
// should be false
System.out.println("Does MORROW have aGoodBase? " + aGoodBase("MORROW"));
// should be true, the check on the base is case insensitive
System.out.println("Does GaTTaca have aGoodBase? " + aGoodBase("GaTTaca"));
// should be false
System.out.println("Does GATMOR have aGoodBase? " + aGoodBase("GATMOR"));
}
}
Output:
Does GATTACA have aGoodBase? true
Does MORROW have aGoodBase? false
Does GaTTaca have aGoodBase? true
Does GATMOR have aGoodBase? false
Now aGoodBase method takes a String and returns true if s contains only a combination of the four basic elements declared in the baseArray array. I've taken the liberty to return true even when the base elements are not in capital letters (as in the third example of the main: GaTTaca).
chardefined?arg[]consist only of AGCT? Or do you want to pass in a single string, and have the method return whether it only contains AGCTs? Or something else?