DNA sequencing programme giving me error

My programme is below… could someone let me know how to edit error?

public class DNA{
String dna;

public DNA(String dnaa){
dna = dnaa;

}
public void proteinpresents(){
int length = dna.length();
int start = dna.indexOf(“ATG”);
System.out.println(“Start” + start);
int stop = dna.indexOf(“TGA”);
System.out.println(“Stop” + stop);
if (start != -1 && stop != -1 &&(stop - start) % 3 == 0){

 String protein = dna.substring(start, stop+3); 
 System.out.println("Protein: " + protein);

} else {
System.out.println(“Protein not present”);

}

}

public static void main(String args){
DNA dna1 = new DNA(“ATGCGATACGCTTGA”);
DNA dna2 = new DNA(“ATGCGATACGTGA”);
DNA dna3 = new DNA(“ATTAATATGTACTGA”);
System.out.println(dna1.proteinpresents());
System.out.println(dna2.proteinpresents());
System.out.println(dna3.proteinpresents());

}
}

Error is "DNA.java:31: error: ‘void’ type not allowed here
System.out.println(dna1.proteinpresents());
^
DNA.java:32: error: ‘void’ type not allowed here
System.out.println(dna2.proteinpresents());
^
DNA.java:33: error: ‘void’ type not allowed here
System.out.println(dna3.proteinpresents());

The problem is that proteinpresents() is a void function, and you are trying to print void (aka nothing). Java is raising an error because it will not let you print a void reference.

Since you are already printing the necessary output inside of your function and are not returning anything, you do not need to print anything inside of the main function.

Instead of System.out.println(dna1.proteinpresents());, try dna1.proteinpresents(); by itself. The same applies for the other two dna strands.

I hope this helps!
Tiger_The_Cat

1 Like