Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i have a problem can you help me . in our uni we have online test that check the code that we write .can you

i have a problem can you help me .

in our uni we have online test that check the code that we write .can you help me what is wrong with this code .

Here is the qustion

Returns the index of the first position in the base DNA string where * candidateDNA can bind, if any.

Here is my code :

package programming.set9.dna;

public class DNAMatcher { private String dnaF = "";

public DNAMatcher(String dnaF) { if (dnaF == "" || dnaF == null) { throw new IllegalArgumentException("Your Dna is not valid "); } char[] dnaInChars = dnaF.toCharArray(); for (int i = 0; i < dnaInChars.length; i++) { if (dnaInChars[i] != 'A' && dnaInChars[i] != 'T' && dnaInChars[i] != 'C' && dnaInChars[i] != 'G') { throw new IllegalArgumentException("Your Dna is not valid "); } } this.dnaF = dnaF; }

public int findFirstBindingPosition(String candidateDNA) { if (candidateDNA == "" || candidateDNA == null) { throw new IllegalArgumentException("Your Dna is not valid "); } char[] dnaInChars = candidateDNA.toCharArray(); for (int i = 0; i < dnaInChars.length; i++) { if (dnaInChars[i] != 'A' && dnaInChars[i] != 'T' && dnaInChars[i] != 'C' && dnaInChars[i] != 'G') { throw new IllegalArgumentException("Your Dna is not valid "); } } int pos = -1, j = 0, k = 0; char cl, cs; boolean found = false;

cl = candidateDNA.charAt(0); while (found != true) { cs = dnaF.charAt(j); if (binden(cl, cs)) { pos = j; found = true; } j++;

if (pos >= 0) { for (k = 1; k < (candidateDNA.length()); k++) { cl = candidateDNA.charAt(k); cs = dnaF.charAt(k + pos); if (k == candidateDNA.length() - 1) { return pos; } if (!binden(cs, cl)) { found = false; break; }

} } }

return pos; }

private boolean binden(char firstDna, char nextDna) { Character.toUpperCase(firstDna); Character.toUpperCase(nextDna); boolean matchDna = false; switch (firstDna) { case 'A': if (nextDna == 'T') matchDna = true; break; case 'T': if (nextDna == 'A') matchDna = true; break; case 'G': if (nextDna == 'C') matchDna = true; break; case 'C': if (nextDna == 'G') matchDna = true; break; default: matchDna = false; break; } return matchDna; } } and here is my tester :

import acm.program.ConsoleProgram;

public class DnaTester extends ConsoleProgram{ public void run(){ DNAMatcher wer = new DNAMatcher("CGGTAATCGCGTATCGAGAG"); println(wer.findFirstBindingPosition("CCATTAGCGCATAGCTC")); DNAMatcher qwe = new DNAMatcher("CGCGTCA"); println(qwe.findFirstBindingPosition("A")); DNAMatcher asd = new DNAMatcher("ATTCCTAATGTCAATT"); println(asd.findFirstBindingPosition("GATTACA"));

} }

Can you help me pleas .

Note the Online test return this exception :

There were 2 failures: 1) Test testIndexOf returned: java.lang.StringIndexOutOfBoundsException: String index out of range: 17

2) Test testIndexOfNonBindingDNA returned: java.lang.StringIndexOutOfBoundsException: String index out of range: 5

Thanks a lot .

i wait for your answer .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions