In this post, you will get all weeks quiz answers of Java Programming: Solving Problems with Software Coursera (Week 2).
Enroll Here: Java Programming: Solving Problems with Software – Coursera
Course overview (All weeks quizzes answers link)
- Week 1: Java Programming: Solving Problems with Software Coursera Quiz answers
- Week 2: Java Programming: Solving Problems with Software Coursera Quiz answers
- Week 3: Java Programming: Solving Problems with Software Coursera Quiz answers
- Week 4: Java Programming: Solving Problems with Software Coursera Quiz answers
Now, let’s start with Week 2 quiz answers which is a part of Java Programming: Solving Problems with Software
Week 2: Java Programming: Solving Problems with Software Coursera Quiz answers
Below you’ll find all practice quiz answers of different topics/sections in Java Programming: Solving Problems with Software Coursera Quiz answers and end quiz exam answers under week 2.
Practice Quiz: Finding a Gene in DNA Quiz Answers Coursera – 6 questions
Q1. Consider the assignment that goes with this lesson and its algorithm for finding a gene with stop codon TAA.
Consider the following DNA string.
- “AAATGCCCTAACTAGATTAAGAAACC”
Which one of the following is the gene returned using that algorithm?
a) ATGCCCTAACTAGATTAA
b) ATGCCC
c) ATGCCCTAA
d) The empty string
e) CCC
Answer: c) ATGCCCTAA
Q2. Which one of the following replaces the String variable dna with the lowercase version of this string?
a) dna = dna.toLowerCase();
b) dna.toLowerCase() = dna;
c) dna.toLowerCase();
d) The empty string
e) dna = dna.toLowerCase(dna);
Answer: a) dna = dna.toLowerCase();
Q3. After adding two additional parameters to findSimpleGene for the startCodon and stopCodon, which of the following is another change that must be made for the program to compile?
a) Two arguments must be added to the call to findSimpleGene.
b) Two if statements must be added to findSimpleGene.
c) Two return statements must be added to findSimpleGene
d) Two if statements must be added to testSimpleGene
Answer: a) Two arguments must be added to the call to findSimpleGene.
Q4. Suppose that stringa is in stringb at position pos. Which one of the following returns the part of stringb that comes after stringa in the method lastPart?
a) return stringb.substring(pos+stringa.length());
b) return stringb.substring(pos);
c) return stringb.substring(pos, stringa.length());
d) return stringb – stringa;
Answer: a) return stringb.substring(pos+stringa.length());
Q5. In the method twoOccurrences, suppose pos is the value of the first occurrence of stringa when stringa is found. Which of the following lines of code assigns pos2 to the second occurrence of stringa if there is a second occurrence?
a) pos2 = stringb.indexOf(stringa, pos+1);
b) pos2 = stringb.indexOf(stringa);
c) pos2 = stringb.indexOf(stringa, pos);
d) pos2 = indexOf(stringb, stringa, pos);
Answer: a) pos2 = stringb.indexOf(stringa,pos+1);
Q6. Consider assignment 2 for this lesson. Consider the code to find and print all the YouTube URL links.
URLResource file = new URLResource("http://someURL");
for (String item : file.words()) {
String itemLower = item.toLowerCase();
int pos = itemLower.indexOf("youtube.com");
if (pos != -1) {
MISSING CODE
}
}
Answer: A
int beg = item.lastIndexOf("\"",pos);
int end = item.indexOf("\"", pos+1);
System.out.println(item.substring(beg+1,end));
Practice Quiz: Finding All Genes in DNA Quiz Answers Coursera – 4 questions
Q1. Which one of the following is the first gene for this strand of DNA where you want to consider all three of the stop codons?
“AATGCTAACTAGCTGACTAAT”
a) The empty string
b) CTAACTAGC
c) ATGCTA
d) ATGCTAACTAGCTGA
e) ATGCTAACTAG
f) ATGCTAA
Answer: d) ATGCTAACTAGCTGA
Q2. Consider the following code segment to count the number of times the string “TG” occurs in the string dna, that does not work correctly.
String dna = "CTGCCTGCATGATCGTA";
int pos = dna.indexOf("TG");
int count = 0;
while (pos >= 0) {
count = count + 1;
pos = dna.indexOf("TG",pos);
}
System.out.println(count);
a) The two lines in the body of the while loop should be swapped so the count happens after pos is given a new value.
b) Each time pos is reset in the while loop it finds the same “TG”.
c) The count is off by 1. The count should be initialized to 1 to take into account the first “TG” that is found.
d) The variable pos should be initialized to 0 in line 2 and only set with indexOf inside the while loop.
Answer: b) Each time pos is reset in the while loop it finds the same “TG”.
Q3. Consider the following segment of code from a program.
while (count < 3) {
count += 1;
newDna = newDna + dna.substring(startPos,pos);
startPos = pos+1;
pos = dna.indexOf("T", startPos);
if (pos == -1) {
break;
}
}
How many different ways are there to break out of this loop?
a) 2
b) 0, it is an infinite loop
c) 1
d) 3
Answer: a) 2
Q4. Which one of the following conditionals correctly evaluates to true if the integer num is an odd number and to false if it is an even number.
a) if (num % 2 == 1)
b) if (num % 2 == 0)
c) if (num % 2 == (num+1) % 2)
d) if (num % 2 == num % 2)
Answer: a) if (num % 2 == 1)
Practice Quiz: Debugging Part 1 Quiz Answers Coursera – 12 questions
Solution Link – Click here!
Practice Quiz: Debugging Part 2 Quiz Answers Coursera – 11 questions
Solution Link – Click here!
Practice Quiz: Using StorageResource Quiz Answers Coursera – 6 questions
Q1. How many genes are there in the file brca1line.fa?
Answer: 1
Q2. How many genes are there in the file brca1line.fa that are longer than 60?
Answer: 1
Q3. How many genes are there in the file brca1line.fa that have a C-G-ratio greater than 0.35?
Answer: 1
Q4. If dna is a String and cgcount is the integer number of C’s and G’s in the String, which one of the following is the correct return statement to return the decimal number of the ratio of C’s and G’s in the string to the length of the string?
a) return double(countcg/dna.length());
b) return countcg / dna.length();
c) return ((double) countcg)/dna.length();
d) return double(countcg)/dna.length();
e) return (double) (countcg / dna.length());
Answer: c) return ((double) countcg)/dna.length();
Q5. Consider the following code where dna is a String. This code attempts to count the number of “C”’s in dna but has an error. It has forgotten to update the variable start.
int countcg = 0;
int start = 0;
while (true) {
int pos = dna.indexOf("C", start);
if (pos == -1) {
break;
}
countcg += 1;
}
Which one of the following best describes how to fix this error?
a) The code start = pos + 1; should go right before the line containing if (pos == -1)
b) The code start = pos; should go immediately after the line containing countcg += 1;
c) The code start = pos; should go right before the line containing if (pos == -1).
d) The code start = pos + 1; should go immediately after the line containing countcg += 1;
e) The code start = pos – 1; should go right before the line containing if (pos == -1).
f) The code start = pos – 1; should go immediately after the line containing countcg += 1.
Answer: d) The code start = pos + 1; should go immediately after the line containing countcg += 1;
Q6. Consider that storeAll is a method that returns a StorageResource of Strings. Which one of the following is a valid statement that would be useful in the storeAll method?
a) StorageResource store = storeAll(s);
b) storeAll(s) = new StorageResource();
c) storeAll(s);
d) String store = storeAll(s);
Answer: a) StorageResource store = storeAll(s);
WEEK 2 QUIZ
Strings in Java Week 2 Quiz Answers Coursera – 7 questions
This is the end quiz of week 2 in Java Programming: Solving Problems with Software Coursera Quiz answers. It is necessary to complete with 80% or higher.
Q1. Consider finding all the YouTube links on a web page. What is the video for the second YouTube link on the web page http://www.dukelearntoprogram.com/course2/data/manylinks.html about?
a) Turkeys, Ducks and Quails
b) STEM
c) Walt Disney cartoons
d) Potatoes
Answer: a) Turkeys, Ducks and Quails
Q2. Consider the following mystery method.
public String mystery(String dna) {
int pos = dna.indexOf("T");
int count = 0;
int startPos = 0;
String newDna = "";
if (pos == -1) {
return dna;
}
while (count < 3) {
count += 1;
newDna = newDna + dna.substring(startPos,pos);
startPos = pos+1;
pos = dna.indexOf("T", startPos);
if (pos == -1) {
break;
}
}
newDna = newDna + dna.substring(startPos);
return newDna;
}
Which of the following best describes what it does?
a) The method mystery is given a string and it returns a string which is three copies of the original string.
b) The method mystery is given a string and it returns a string which is the same string but with the each T each replaced with two T’s.
c) The method mystery is given a string and it returns a string which is the same string but with the first three T’s removed.
d) The method mystery is given a string and it returns a string which is the same string but with the first three T’s each replaced with two T’s.
e) The method mystery is given a string and it returns a string which is the same string but with all the T’s removed.
Answer: c) The method mystery is given a string and it returns a string which is the same string but with the first three T’s removed.
Q3. Use the following data file to answer this question: http://www.cs.duke.edu/~rodger/GRch38dnapart.fa. How many genes are in this file?
Answer: 69
Q4. Use the following data file to answer this question: http://www.cs.duke.edu/~rodger/GRch38dnapart.fa. How many genes in this file are longer than 60?
Answer: 23
Q5. Use the following data file to answer this question: http://www.cs.duke.edu/~rodger/GRch38dnapart.fa. How many genes in this file have cgRatio greater than 0.35?
Answer: 40
Q6. Use the following data file to answer this question which represents one long strand of DNA: http://www.cs.duke.edu/~rodger/GRch38dnapart.fa. How many times does the codon CTG appear in this strand of DNA?
Answer: 224
Q7. Use the following data file to answer this question: http://www.cs.duke.edu/~rodger/GRch38dnapart.fa. What is the length of the longest gene in the collection of genes found in this file?
Answer: 489
>> Next: WEEK 3: Java Programming: Solving Problems with Software Coursera Quiz answers
Explore! Artificial Intelligence Foundations Exams answers – SkillUp
The above question set contains all the correct answers. But in any case, you find any typographical, grammatical or any other error then kindly inform us.
Thanks in advance.
If you need answers of any exam then let me know through contact us page.
For discussion about any question, join the below comment section. And get the solution of your query. Also, try to share your thoughts about the topics covered in this particular quiz.