Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using java please public class Tester { private static int numFailed = 0; private static int numSuccess = 0; private static int total = 0;

using java please

image text in transcribedimage text in transcribed

public class Tester { private static int numFailed = 0; private static int numSuccess = 0; private static int total = 0;

public static void main(String[] args) { // test isDna: reportTest(DnaSequence.isDnaSequence("acgt"), 1); reportTest(!DnaSequence.isDnaSequence("hello hello"), 2); DnaSequence gene1 = new DnaSequence("ACGtTgAaT"); DnaSequence gene2 = new DnaSequence("ACGTHELLO"); DnaSequence gene3 = new DnaSequence("ACGT"); // test initialization & toString(): reportTest(gene3.toString().equals("ACGT: (1, 1, 1, 1)"), 3); reportTest(gene2.toString().equals("ACGT: (1, 1, 1, 1)"), 4); reportTest(gene1.toString().equals("ACGtTgAaT: (3, 1, 2, 3)"), 5); // test copy constructor: DnaSequence gene4 = new DnaSequence(gene3); reportTest(areEqualArrays(gene3.getNucleotideCounts(), gene4.getNucleotideCounts()), 6); // test changeCapitalization(): gene1.changeCapitalization(); reportTest(gene1.toString().equals("acgTtGaAt: (3, 1, 2, 3)"), 7); gene2.changeCapitalization(); reportTest(gene2.toString().equals("acgt: (1, 1, 1, 1)"), 8); // test get & set: int[] arr = {1, 1, 1, 1}; reportTest(areEqualArrays(gene3.getNucleotideCounts(), arr), 9); reportTest(gene1.getSequence().equals("acgTtGaAt"), 10); gene3.setSequence("tgagtGGGGca"); reportTest(gene3.getSequence().equals("tgagtGGGGca"), 11); int[] newCounts = {2, 1, 6, 2}; reportTest(areEqualArrays(gene3.getNucleotideCounts(), newCounts), 12);

// test addArray: int[] arr1 = {1, 2, -3, 4}; int[] arr2 = {0, -2, 4, 6}; int[] resSum = {1, 0, 1, 10}; DnaSequence.addArray(arr1, arr2); reportTest(areEqualArrays(arr1, resSum), 13); // test concatGenes: gene1.concatGenes(gene2); int[] res = {4, 2, 3, 4}; reportTest(areEqualArrays(gene1.getNucleotideCounts(), res), 14); reportTest(gene1.getSequence().equals("acgTtGaAtacgt"), 15);

System.out.println("Num. test failed: " + numFailed); System.out.println("Num. test passed: " + numSuccess); System.out.println("Num. total tests: " + total); System.out.println("Original tester is done! Now you can add more tests."); }

/** * The method reports if the test failed or passed, according to the given condition. * @param condition Condition to check. False value means that the test has failed. * @param testNum Test number. */ private static void reportTest(boolean condition, int testNum) { total++; if(! condition) { System.err.println("FAILED TEST " + testNum + "."); numFailed++; } else { System.out.println("PASSED TEST " + testNum + "."); numSuccess++; } } private static boolean areEqualArrays(int[] arr1, int[] arr2) { if(arr1 == null || arr2 == null) return false; if(arr1.length != arr2.length) return false; for (int i = 0; i Exercise home number 8 Study material for the exercise: Recursion In this exercise it is forbidden to use loops. A solution with loops will not be accepted. In terms of working with the String class, only methods, (charAt (), indexOf .length (), substring() Question 1 (100%) Write a class called DnaSequence which represents a sequence of DNA (DNA). DNA is the genetic material that appears in every living cell. From our point of view, this is a string consisting of only 4 letters: M, A, C, G (lower or upper case). A valid DNA sequence contains only these letters. These letters are called nucleotides. Studies in genetics and bioinformatics analyze such sequences and compute a variety of statistics. For example, we would like to calculate how many times each letter appears in the sequence. Fields The class contains two private fields: a. sequence - the DNA sequence that the class represents (String type) B. nucleotideCounts - A one-dimensional array of integers that counts how many times each letter appears in the sequence. The first place counts how many times the letter A (small or large) appears, the second place counts how many times the letter C (small or large) appears, the third place counts how many times the letter G (small or large) appears, and the fourth place counts how many times the letter T appears (Small or large). Constructors 1. An empty constructor which initializes the sequence sequence to be "ACGT" and the array accordingly. Builder Signature: public DnaSequence () 2. A builder who gets a sequence. If it is a valid DNA sequence, it initializes both fields accordingly. Otherwise, the initialization is done as in the blank constructor. Builder signature: public DnaSequence (String sequence) 3. Copy builder: public Dna Sequence (Dna Sequence other) Methods 1. get methods for the fields: public String getSequence () public int [] getNucleotideCounts() 2. Set method for the sequence: public void set Sequence (String sequence) Notes: 1. Depending on the sequence update, the counts field must also be updated according to the new sequence. 2. The update is performed only if the sequence parameter is a valid DNA sequence. Otherwise, the function does not change the object. 3. A static method that receives a string and checks whether it is a valid DNA sequence. Signature of the method: public static boolean isDna Sequence (String sequence) 4. A method that turns each small letter in sequence into a capital letter and vice versa. Signature of the method: public void changeCapitalization () 5. A static method that accepts 2 arrays and adds the second to the first, without changing the second. If one of the arrays is null or the arrays are not the same length, the method returns false. Otherwise, true will be returned. Signature method: public static boolean addArray (int[] arri, int [] arr2) 6. A method that chains a DNA sequence at the end of the sequence of this. In addition, the method updates the counts using the method from section 5. Signature of the method: public void concatGenes (Dna Sequence other) 7. The toString method, which returns string production for the object, contains the same sequence information and about the counts in the format: : (, , , ) Where is the sequence, is the number of occurrences of "A" or "a", etc. For example, for an object representing the "ACGT" sequence the string would be: ACGT: (1, 1, 1, 1) Method signature: public String toString()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Students also viewed these Databases questions