DNA Sequencing Solution

My solution for this exercise.

public class DNA {

  
  public static void main(String[] args) { 
    
    String[] dnaList = {"ATGCGATACGCTTGA", "ATGCGATACGTGA", "ATTAATATGTACTGA"};
        
    for (String dna : dnaList) {
      int proteinHeaderSearcher = dna.indexOf("ATG");
      // if header start with "ATG" && footer end with "TGA" && length % 3 == 0 then it's DNA protein.
      if (dna.substring(proteinHeaderSearcher, proteinHeaderSearcher + 3).equals("ATG") && dna.substring(dna.length() - 3).equals("TGA") && dna.length() % 3 == 0) {
      System.out.println(dna + " sample is DNA protien");
      } else {
      System.out.println(dna + " sample is not DNA protein");
      }
    }
  }
}

I created a fully working solution for this project. It’s a bit off from the suggested steps, but it does the job well. Also, it uses a couple of concepts from previous lessons. I wonder what other people think.

import java.util.ArrayList;
public class DNA {

// This is a DNA Sequencing project

  public DNA() {}

  public static void main(String[] args) {
    ArrayList<String> dna = new ArrayList<String>();
    dna.add("ATGCGATACGCTTGA");
    dna.add("ATGCGATACGTGA");
    dna.add("ATTAATATGTACTGA");

    for (String item : dna) {
      if (item.indexOf("ATG") != -1 && item.indexOf("TGA") != -1 && (item.indexOf("TGA") - item.indexOf("ATG")) % 3 == 0) {

     System.out.println("We have a winner!");
      
    } else {
      System.out.println("There is no protein.");
    }

   }
   
  }

}