- Start with this code
public class DNA {
public static void main(String[] args) {
// -. .-. .-. .-. .
// \ \ / \ \ /
// / \ \ / \ \
// ~ `-~ `-` `-~ `-
}
}
-
Write a comment near the top of the program that describe what the program does.
-
Here are the three DNA strands that you are going to use to test your program:
"ATGCGATACGCTTGA"
"ATGCGATACGTGA"
"ATTAATATGTACTGA"
Store them in different strings:
dna1
,dna2
, anddna3
. -
Create a generic
String
variable calleddna
that can be set to any DNA sequence (dna1
,dna2
,dna3
). -
To warm up, find the length of the
dna
string. -
Remember that a protein has the following qualities:
- It begins with a start codon
ATG
. - It ends with a stop codon
TGA
. - In between, the number of nucleotides is divisible by 3.
First, let’s start with the first condition. Does the DNA strand have the start codon
ATG
within it?Find the index where
ATG
begins usingindexOf()
. - It begins with a start codon
-
Next, does the DNA strand have the stop codon
TGA
?Find the index where
TGA
begins. -
Lastly, you’ll find out whether or not there is a protein!
Let’s start with an
if
statement that checks for a start codon and a stop codon using the&&
operator.Remember that the
indexOf()
string method will return-1
if the substring doesn’t exist within aString
. -
Add a third condition that checks whether or not that the number of nucleotides in between the start codon and the stop condon is a multiple of 3.
Remember that the modolo operator
%
returns the remainder of a division. -
Inside the
if
statement, create aString
variable namedprotein
.And find this protein in the
dna
by using thesubstring()
string method. Think about where you want the substring to begin and where you want the substring to end.Remember that a codon is 3 nucleotides long.
-
Add an
else
clause that print outNo protein.
. -
You are all done!
Let’s test your code with each DNA strand. These should be the results:
dna1
: Contains a protein.dna2
: Does not contain a protein.dna3
: Contains a protein.