Hi, I’m new to Codecademy and just new to programming in general. I have never posted on a forum like this before either!

I’m completely noob at this. But… I’m thoroughly enjoying my self taught journey to becoming, hopefully one day, a fully fledged Software Developer. I wanted to share my embarrassing attempt for the DNA Sequencing, String Methods, Java exercise. Now, I know this attempt is pathetic and the code is so repetitive and completely not the correct way to do it. But… I was so proud the fact that I managed to do it completely without looking at the guide… from scratch.

Check out my attempt below and please do have a laugh :slight_smile: Im also to looking to make some new friends on this, perhaps those who are similar to me in experience and we can learn together? Do hit me up!

Also: any feedback, advises, recommendations would be welcomed !

public class DNA {

  public static boolean first3(String dNa) {
    return true;

  public static boolean last3(String dNa) {
    return true;

  public static boolean checkSize(String dNa) {
	  int size = dNa.length();
	  if (size % 3 == 0) {
		  return true;
	  } else {
		 return false;	  

  public static void main(String[] args) {

    String sample1 = "ATGCGATACGCTTGA";
    String sample2 = "ATGCGATACGTGA";
    String sample3 = "ATGCGATACGTGA";
    boolean condition1 = first3(sample1);
    boolean condition2 = last3(sample1);
    boolean condition3 = checkSize(sample1);
    if (condition1 && condition2 && condition3) {
    	System.out.println(sample1 + " is a protien");
    } else {
    	System.out.println(sample1 + " is not a protien");
    boolean condition4 = first3(sample2);
    boolean condition5 = last3(sample2);
    boolean condition6 = checkSize(sample2);
    if (condition4 && condition5 && condition6) {
    	System.out.println(sample2 + " is a protien");
    } else {
    	System.out.println(sample2 + " is not a protien");
//has to start with ATG
//has to end with TGA
//length must be divisible by 3
//print "is a Protein"
//else print "is not a Protein"

1 Like

Welcome to the forums! It’s great that you’re learning to code and attempted this without any hints; there’s just one thing I’d like to point out.

Your first3() and last3() methods don’t actually return true if the DNA sequences are valid and false otherwise. I’ll show this using first3() but the same reasoning can be applied to last3().

The above code calls the .equals() method on the parameter. .equals() returns true if the string passed in is exactly equal in value to, in this case, "ATG". Firstly, you only want to check if the first three characters in the string dNa are equal to "ATG", not whether the whole string is equal to "ATG".

Secondly, true will always be returned from the method because the return true statement will be executed no matter what. When you call dna.equals("ATG"), it simply executes the .equals() method and then does nothing with what is returned from that method call. We want to return true only if the first three characters in dNa are equal to "ATG" and return false if they are not equal.

What changes do you need to make to your code?

1 Like