Data Structures and Performance | Week 2
Course Name: Data Structures and Performance
Course Link: Data Structures and Performance
These are Data Structures and Performance Week 2 Coursera Answers
Programming Assignment: How Easy to Read is Your Writing?
Steps: Create two java files BasicDocument.java and Document.java, create a zip file of both documents and upload in same zip file in both columns
BasicDocument.java:
package document;
import java.util.List;
public class BasicDocument extends Document
{
public BasicDocument(String text)
{
super(text);
}
@Override
public int getNumWords()
{
List<String> tokens = getTokens("[a-zA-Z]+");
return tokens.size();
}
@Override
public int getNumSentences()
{
List<String> tokens = getTokens("[^!?.]+");
return tokens.size();
}
@Override
public int getNumSyllables()
{
List<String> tokens = getTokens("[aeiouyAEIOUY]+");
List<String> loneEs = getTokens("[^aeiouyAEIOUY]+[eE]\\b");
List<String> singleEs = getTokens("\\b[^aeiouyAEIOUY]*[eE]\\b");
return tokens.size() - (loneEs.size() - singleEs.size());
}
public static void main(String[] args)
{
testCase(new BasicDocument("This is a test. How many??? "
+ "Senteeeeeeeeeences are here... there should be 5! Right?"),
16, 13, 5);
testCase(new BasicDocument(""), 0, 0, 0);
testCase(new BasicDocument("sentence, with, lots, of, commas.! "
+ "(And some poaren)). The output is: 7.5."), 15, 11, 4);
testCase(new BasicDocument("many??? Senteeeeeeeeeences are"), 6, 3, 2);
testCase(new BasicDocument("Here is a series of test sentences. Your program should "
+ "find 3 sentences, 33 words, and 49 syllables. Not every word will have "
+ "the correct amount of syllables (example, for example), "
+ "but most of them will."), 49, 33, 3);
testCase(new BasicDocument("Segue"), 2, 1, 1);
testCase(new BasicDocument("Sentence"), 2, 1, 1);
testCase(new BasicDocument("Sentences?!"), 3, 1, 1);
testCase(new BasicDocument("Lorem ipsum dolor sit amet, qui ex choro quodsi moderatius, nam dolores explicari forensibus ad."),
32, 15, 1);
}
}
These are Data Structures and Performance Week 2 Coursera Answers
Document.java:
Answer: Please login to see answer.
These are Data Structures and Performance Week 2 Coursera Answers
Module and Programming Assignment Quiz
Q1. What will be printed by the following code? Of course, you can run this code and get the question right, but we want you to answer this question (and all of these questions) without running the code.
String s1 = new String("String 1");
String s2 = "String 1";
if (s1 == s2) {
System.out.println("Equal");
else {
System.out.println("Not equal");
}
- Not equal
- Equal
Answer: Please login to see answer.
Q2. Which of the following lines of code correctly assign a String containing the text “My String” to the variable ‘text’?
(Select all correct options.)
Answer:
Answer: Please login to see answer.
Answer: Please login to see answer.
These are Data Structures and Performance Week 2 Coursera Answers
Q3. What best describes the functionality of the following method?
public int mystery(String s)
{
char[] letters = s.toCharArray();
int x = 0;
for (int i = 0; i < letters.length; i++) {
if (letters[i] == ' ') {
letters[i] = '_';
x++;
}
}
return x;
}
- It counts the number of spaces in a given string, and returns the count. It does not change the original String.
- It counts the number of spaces in a given String and returns the count. It also replaces all spaces in the given String with underscore characters (‘_’).
- It counts the number of total characters in the String and returns the count. It also replaces all spaces in the given String with underscore characters (‘_’).
Answer: Please login to see answer.
These are Data Structures and Performance Week 2 Coursera Answers
Q4. Assume you have a String variable s that stores the text
“%one%%two%%%three%%%%”
Which of the following calls to s.split will return the String array:
[“%”, “%%”, “%%%”, “%%%%”]
(Select all correct options.)
Answer:
Answer: Please login to see answer.
Answer: Please login to see answer.
These are Data Structures and Performance Week 2 Coursera Answers
Q5. Assume that you have a Document object stored in the variable d, whose whole text string is
“one (1), two (2), three (3)”
Which of the following calls to getTokens will return the list of Strings given here:
[“one”, “(1)”, “two”, “(2)”, “three”, “(3)”]
Pay attention to the spaces in the original string, and also notice the commas are not preserved in the strings in the list.
(Select all correct options.)
Answer:
Soon
These are Data Structures and Performance Week 2 Coursera Answers
Q6. Does a higher or lower Flesch Index Score indicate simpler text?
- The higher the Flesch Index Score, the simpler the text and the easier it is to read.
- The lower the Flesch Index Score, the simpler the text and the easier it is to read.
Answer: Please login to see answer.
These are Data Structures and Performance Week 2 Coursera Answers
Q7. How much time did you spend on the programming assignment?
- <1 hour
- 1-2 hours
- 2-3 hours
- 3-4 hours
- 4-5 hours
- 5+ hours
Answer: Please login to see answer.
These are Data Structures and Performance Week 2 Coursera Answers
Q8. How difficult did you find the programming assignment?
- Very Easy
- Easy
- Somewhat Easy
- Somewhat Difficult
- Difficult
- Very Difficult
Answer: Please login to see answer.
These are Data Structures and Performance Week 2 Coursera Answers
Q9. How much did you enjoy the programming assignment?
- I really enjoyed the programming assignment
- I enjoyed the programming assignment
- I’m neutral about the programming assignment
- I did not enjoy the programming assignment
- I really did not enjoy the programming assignment
Answer: Please login to see answer.
These are Data Structures and Performance Week 2 Coursera Answers
More Weeks of the course: Click Here
More Coursera courses: https://progiez.com/coursera
![Data Structures and Performance | Week 2 1 Data Structures and Performance Week 2 Coursera Answers](https://progiez.com/wp-content/uploads/2023/01/cropped-3-progiez-logo.png-1.png)