how to write a method in Java The first part of your DNA ana

how to write a method in Java
The first part of your DNA analysis program is going to be finding the longest terminating overlap between the DNA you have so far the new DNA the sequencer gives you Look at the following example We start with no DNA Your DNA Sequencer DNA \'ATATATATA* New Sequence \'ATATATATA\' Your DNA -ATATATATA* Sequencer DNA \'ATACATGA\" New Sequence \'ATATATATACATGA* Your ONA: \'ATATATATA* Sequencer ONA \"ATACAT6A* New Sequence: \"ATATATATACATGA*

Solution

static String solution(String DNA1, String DNA2) {
       // Calculated length of DNAs as
       // it will be useful at multiple places.
       int DNA1Length = DNA1.length();
       int DNA2Length = DNA2.length();
      
       /*
       * Handled corner cases
       * Ex. if DNA1 = \"\"
       *     And DNA2 = \"ATATATATA\"
       *     Then return \"ATATATATA\"
       */
       if (DNA1Length == 0) {
           return DNA2;
       } else if (DNA2Length == 0) {
           return DNA1;
       } else if (DNA1.equals(DNA2)) {
           return DNA1;
       }
      
       /*
       * This for loop will try to find
       * longest terminating overlap between DNAs.
       * It will start with minimum length of both DNAs
       * and keep decrementing one.
       * It will check if DNA1 ends with any substring of DNA2.
       *
       * if it has any overlap then,
       * it will return DNA1 + remaining part of DNA2.
       *
       * else it will return concatenation of DNA1 and DNA2.
       */
       for (int i = Math.min(DNA1Length, DNA2Length); i > 0 ; i--) {
           if(DNA1.endsWith(DNA2.substring(0, i)) ) {
               return DNA1 + DNA2.substring(i);
           }
       }
       return DNA1 + DNA2;
   }

how to write a method in Java The first part of your DNA analysis program is going to be finding the longest terminating overlap between the DNA you have so far

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site