Hi, we're going to find a gene in a DNA strand. We're going to do a very simple algorithm in order to find our gene. So I've started some code here. We have an algorithm method, called findGeneSimple. And we haven't done much with it yet, but what I've also done down here is I've written a couple of DNA strands that we will use to test the code that we write. So you can see here we have String dna. We're going to print our DNA stand. We're going to call findGeneSimple and then print out our gene. And then I just have done this with four different strands of DNA. So let's write the code now. So I've started by just saying, the resulting gene is just going to be called a variable called result. And I've set it to null, the null string. And if you remember from the video, we are going to look for the start codon in the strand of DNA. And the start codon is ATG, the string ATG. So we can use the new string functions that we learned about. So I'm going to start by creating a variable that will hold the index position of the start codon. So we'll call it startIndex, and then we are going to look in the strand of DNA and we'll use the indexOf function to look for ATG. And the indexOf function is going to go through the string and it's going to stop when it finds ATG and it's going to return the index location of where it starts. So that'll be the starting position of our gene. We also have to look for the stop codon, and that is TAA. So we're going to create a variable for that called stopIndex, For the position of where the stop codon is. Again we will look in our DNA strand, DNA and we'll use indexOf. But if you just look for TAA, it will start at the beginning of the string. And we want to look for the stop codon after the start codon. So we know where the start codon is. It's in the variable startIndex. And we want to start looking past that. So you can add a second parameter to the indexOf function, and so we will add that and say, start looking where ATG is, which is startIndex. +3, which is the length of ATG. So now we have the startIndex and the stopIndex, startIndex of ATG and the stopIndex of TAA. And now we want the strand that includes those two and everything in between it. So I'm going to call that our result. Again we'll use a string function. So we'll use the string function called substring. And the way substring works is you have to say I want a piece of a string and I want to start, where do we want to start? We want to start where ATG is, so we'll start at the startIndex and then the rest of our gene is going to be everything past ATG up until TAA, which is at the stopIndex. But we also want to include TAA so we'll add 3. So that means take our substring from where ATG starts, go all the way to the stopIndex +3, which is the first character after TAA. And the way substring works is it says start at the first StartIndex and then go all the way up to, but not including, the second parameter. And then let's compile this and see if it works. Okay, so it compiles fine. So let's go over here, and we'll create a new findGene. And now we'll run our test method that we wrote. And there it is. So we can see, here's the first DNA strand. And you look for ATG, there it is. And then look for TAA and there's the first TAA that's after it. And you can see there's the gene that we found, right here. And then the next example here's ATG. We look for TAA all the way here. And you can see here that's the gene we found. Here's the third example, ATG all the way to TAA. You can see that we've got a big gene there. And then here's the last example. ATGTAA so that works good too. But what happens if ATG is not there? Or what happens if TAA is not there? So let's look at our example here, and let's change one of our strings. Let's change this string. We'll just save this one. And let's change it to, A string that does not have ATG in it. Let's see what happens if we run that example. So we're going to come back over here. And we'll run our testFind, and we got an error down here. You can see, it says StringIndexOutOfBoundsException,- 1. String index out of range. What happened? Let's go look at our code. So we looked for ATG and we didn't find it. And what the indexOf function does if it doesn't find the string you are looking for, it returns -1. So startIndex has the value -1 and then we are trying to build a string starting at -1 and -1 doesn't exist. So we got an error. So what are we going to do? We need to fix this code. So let's check right after we ask for ATG, let's put an if statement in there to check to make sure that ATG was there. So we can ask if startIndex Is equal to -1, that means there is no ATG. In that case, there is no gene. There's no gene if there's no ATG, there's no start. So what we'll do is we'll just return the empty string. So if you compile this now and if we run it. So we'll create findGene. And then we'll run testFind, and it ran, but there's no gene here. That's because there's no ATG. Let's try another example. We'll change our code again to give another example. Let's just change this one here. Let's create a string where we have ATG but we don't have TAA. So we have the start codon, but not the stop codon. So I'll create a string, CGATGGTTTAAAAGT. So there's no, there is, let's get rid of it. G, there we go. So now we have ATG right here and to the right of it there is no TAA. So let's compile and we'll run it. And you can see it's not there. There's no gene for the second one because ATG, but there's no TAA. All right, so just like we put a check for if there's no ATG, we should do the same for if there's no stop codon, so no TAA. So let's add that code, too. We would add it right after we get the value for stop codon. So right here we can check and see if stop. If the stopIndex equals -1, at that point we know there's no stop codon and so there's no gene. And so we can again, just return the empty string. Return, Empty string. So that's just a safe way, if there's no start codon, or no stop codon. Let's add a comment here. This is a case for no TAA. We'll compile our code and we'll just double check and make sure that works. So it compiles and we'll run it. And now we have, our first string is good, we find a gene. Our second string, there is no gene. We have an ATG but we don't have a TAA. This string looks good. The string has no ATG. It actually does have a TAA but that doesn't matter because it has no ATG. And so there is no gene for that one either. So anyway that is the way to find a simple gene and a strand of DNA. We look for the start codon and then if there's a start codon, we look past it for the stop codon. And if we find both of those, then we can return the start codon, the stop codon, and everything in between it as the gene. Thank you.