DNA Max Write code to find which of the strands representing DNA in an array String[] strands representing strands of DNA has the most occurrences of the nucleotide represented by parameter nuc. Complete the definition of the class DnaMax and method definition maxStrand shown below. If more than one strand has the same maximal number of the specified nucleotide you should return the longest strand with the maximal number. All DNA strands have different lengths in this problem so the maximal strand will be unique when length is accounted for. Return this uniquely maximal strand. Each String representing a DNA strand will contain only cytosine, guanine, thymine, and adenine, represented by the characters 'c', 'g', 't', and 'a', respectively. If no strand in the array contains the specified nucleotide return the empty string "". public class DnaMax { public String maxStrand(String[] strands, String nuc) { // fill in code here } } Constraints strands will contain no more than 50 elements, each element will be a different length and the characters of the the strings will only be 'a', 'g', 't', or 'c'. nuc will be a one character string, either "a", "g", "t", or "c". Example 1 strands = {"agt", "aagt", "taattt", "ccatg" } nuc = "a" Returns "taattt" since both "aagt" and "taattt" have two occurrences of 'a', but "taattt" is longer. Example 2 strands = {"agt", "aagt", "taattt", "ccatc" } nuc = "g" Returns "aagt" since both "aagt" and "agt" have one occurrence of 'g', but "aagt" is longer. Example 3 strands = {"g", "gg", "ggg", "gggg"} nuc = "c" Returns "" because the nucleotide "c" doesn't occur in any strand.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

DNA Max

Write code to find which of the strands representing DNA in an array String[] strands representing strands of DNA has the most occurrences of the nucleotide represented by parameter nuc. Complete the definition of the class DnaMax and method definition maxStrand shown below.

If more than one strand has the same maximal number of the specified nucleotide you should return the longest strand with the maximal number. All DNA strands have different lengths in this problem so the maximal strand will be unique when length is accounted for. Return this uniquely maximal strand.

Each String representing a DNA strand will contain only cytosine, guanine, thymine, and adenine, represented by the characters 'c', 'g', 't', and 'a', respectively. If no strand in the array contains the specified nucleotide return the empty string "".

public class DnaMax { public String maxStrand(String[] strands, String nuc) { // fill in code here } }

Constraints

  • strands will contain no more than 50 elements, each element will be a different length and the characters of the the strings will only be 'a', 'g', 't', or 'c'.
  • nuc will be a one character string, either "a", "g", "t", or "c".

Example 1

strands = {"agt", "aagt", "taattt", "ccatg" } nuc = "a"

Returns "taattt" since both "aagt" and "taattt" have two occurrences of 'a', but "taattt" is longer.

Example 2

strands = {"agt", "aagt", "taattt", "ccatc" } nuc = "g"

Returns "aagt" since both "aagt" and "agt" have one occurrence of 'g', but "aagt" is longer.

Example 3

strands = {"g", "gg", "ggg", "gggg"} nuc = "c"

Returns "" because the nucleotide "c" doesn't occur in any strand.

45678
9
10
11
DAHED=998~~~
12
13
14
15
16
17
18
19
20
21
22
23
public class DnaMax {
// find strand with most occurrences of substring nuc
public String maxStrand (String[] strands, String nuc) {
// TODO: fill in method definition; replace placeholder on next line
return "";
}
}
Run | Debug
public static void main(String[] args) {
DnaMax dna = new DnaMax();
String[] strands1 = {"agt", "aagt", "taattt", "ccatg" };
String[] strands2 = {"agt", "aagt", "taattt", "ccatc" };
String[] strands3 = {"g", "gg", "ggg", "gggg" };
System.out.println(dna.maxStrand
System.out.println(dna.maxStrand
System.out.println(dna.maxStrand
(strands1, nuc: "a"));
(strands2, nuc: "g"));
(strands3, nuc: "c"));
}
Transcribed Image Text:45678 9 10 11 DAHED=998~~~ 12 13 14 15 16 17 18 19 20 21 22 23 public class DnaMax { // find strand with most occurrences of substring nuc public String maxStrand (String[] strands, String nuc) { // TODO: fill in method definition; replace placeholder on next line return ""; } } Run | Debug public static void main(String[] args) { DnaMax dna = new DnaMax(); String[] strands1 = {"agt", "aagt", "taattt", "ccatg" }; String[] strands2 = {"agt", "aagt", "taattt", "ccatc" }; String[] strands3 = {"g", "gg", "ggg", "gggg" }; System.out.println(dna.maxStrand System.out.println(dna.maxStrand System.out.println(dna.maxStrand (strands1, nuc: "a")); (strands2, nuc: "g")); (strands3, nuc: "c")); }
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Card {
// min/max for the card number range
private static final int MIN_NUMBER = 1;
private static final int MAX_NUMBER = 13;
private int number;
private String suit;
/**
* Create a new card with number and suit. If the a valid
* suit/number is not input, the card defaults to 1 of hearts.
*
* @param number the card number
* @param suit the card suit
*/
public Card (int number, String suit) {
this.number = number;
this.suit = suit.toLowerCase();
if (!isValidSuit (suit)) {
System.out.println(suit + "Is not a valid suit!");
System.out.println(x: "Must be one of: clubs, diamonds, hearts or spades");
System.out.println(x: "Defaulting to hearts");
this.suit = "hearts";
}
Transcribed Image Text:8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 public class Card { // min/max for the card number range private static final int MIN_NUMBER = 1; private static final int MAX_NUMBER = 13; private int number; private String suit; /** * Create a new card with number and suit. If the a valid * suit/number is not input, the card defaults to 1 of hearts. * * @param number the card number * @param suit the card suit */ public Card (int number, String suit) { this.number = number; this.suit = suit.toLowerCase(); if (!isValidSuit (suit)) { System.out.println(suit + "Is not a valid suit!"); System.out.println(x: "Must be one of: clubs, diamonds, hearts or spades"); System.out.println(x: "Defaulting to hearts"); this.suit = "hearts"; }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education