So I am having trouble with the second part of this project. I have the below code which gives counts for each entry, but I do not know how to get the highs and lows...Thanks in advance!
A1Adept
This program should process the input as A1Novice does, but in addition to producing the counts, it should also keep track of the DNA strand with the smallest and largest number of each of the nucleobases and print those strands to the output. So, given the following input:
A
CC
AATA
GGG
TTT
end
The program should produce the following output:
A count: 4
C count: 2
G count: 3
T count: 4
Low A count: A
High A count: AATA
Low C count: CC
High C count: CC
Low G count: GGG
High G count: GGG
Low T count: AATA
High T count: TTT
package a1;
import java.util.Scanner;
public class A1Novice {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
System.out.println("Enter nucleobases: (enter end when done)");
process(s);
}
public static void process(Scanner s){
int a = 0, c = 0, g = 0, t = 0;
while(s.hasNext()){
String id = s.next();
if(id.equalsIgnoreCase("end")){
break;
}
for(int i = 0; i < id.length(); i++){
char singleChar = id.charAt(i);
if (singleChar=='A' || singleChar=='a'){
a++;
}
else if(singleChar=='C' || singleChar=='c'){
c++;
}
else if(singleChar=='G' || singleChar=='g'){
g++;
}
else if(singleChar=='T' || singleChar=='t'){
t++;
}
}
}
System.out.println("A count: " + a);
System.out.println("C count: " + c);
System.out.println("G count: " + g);
System.out.println("T count: " + t);
}
}