Java Programming Principle Software Design Coursera Quiz

Hello Students, Today we are going to share all week evaluation and quiz answers of Java Programming Principles Software Design course started by Coursera completely free of cost. This is a certification course for every aspiring students.

If you did not get this course for free, you can apply for financial advertisements to get this course completely free.

Coursera, India’s largest learning platform, launched millions of free courses for students every day. These courses are from various recognized university, where industry experts and professors teach in a very good manner and in a more understandable manner.

Here, you will get the Java Programming Principles Software Design Exam Answers in bold color which are given below.

These are the answers to Java Programming Principles Software Design questions from Coursera’s free certification course. These answers have been updated recently and are 100% correct. The final exam is on Monday, April. All answers are 100%.

Java Programming Principles Software Design Quiz

Week- 1

Earthquakes: Programming and Interfaces


Question1: For the assignment you wrote the method quakesByPhrase to print all the earthquakes from a data source whose title has a phrase in it at a specified location, and also to print out the number of earthquakes found. Modify this method to run your program on the file nov20quakedata.atom (a file with information on 1518 quakes) for quakes with the phrase “Alaska” at the end of the earthquake’s title.

How many such earthquakes are there?

1 point
Enter answer here

364

Question 2: For the assignment you wrote the method quakes Of Depth to print all the earthquakes from a data source whose depth is between a given minimum and maximum value, and also to print out the number of earthquakes found. Modify this method to run your program on the file nov20quakedata.atom (a file with information on 1518 quakes) for quakes with depth between -12,000.0 and -10,000.0, exclusive.

How many such earthquakes are there?

1 point
Enter answer here

127


Question 3. For the assignment you wrote the method quakes of Depth to print all the earthquakes from a data source whose depth is between a given minimum and maximum value, and also to print out the number of earthquakes found. Modify this method to run your program on the file nov20quakedata.atom (a file with information on 1518 quakes) for quakes with depth between -4000.0 and -2000.0, exclusive.

How many such earthquakes are there?

1 point
Enter answer here

157


Question 4 : For the assignment you wrote the method findLargestQuakes to print a given number of earthquakes from a data source in order from largest magnitude. Modify this method to run your program on the file nov20quakedata.atom (a file with information on 1518 quakes) for the 20 earthquakes with the largest magnitude.

What was the magnitude of the 20th largest earthquake?

1 point
Enter answer here

5.10

Question 5: For the assignment you wrote the method quakes By Phrase to print all the earthquakes from a data source whose title has a phrase in it at a specified location, and also to print out the number of earthquakes found. Modify this method to run your program on the file nov20quakedata.atom (a file with information on 1518 quakes) for quakes with the phrase “Quarry Blast” at the start of the earthquake’s title.

How many such earthquakes are there?

1 point
Enter answer here

19

Question 6 :For the assignment you wrote the method quakesByPhrase to print all the earthquakes from a data source whose title has a phrase in it at a specified location, and also to print out the number of earthquakes found. Modify this method to run your program on the file nov20quakedata.atom (a file with information on 1518 quakes) for quakes with the phrase “Can” as a substring anywhere in the earthquake’s title.

How many such earthquakes are there?

1 point
Enter answer here

58


Question 7 : For the assignment you wrote the method quakesWithFilter in the class EarthQuakeClient2 to filter earthquakes using two criteria. Modify that critieria to be magnitude between 3.5 and 4.5 inclusive and depth between -55,000.0 and -20,000.0 inclusive. Run your program on the file nov20quakedata.atom (a file with information on 1518 quakes) with this criteria. You should also print out the number of such earthquakes found.

How many such earthquakes are there?

1 point
Enter answer here

15


Question 8 : Suppose one adds the getName( ) method to the Filter interface and adds a String parameter to the constructor of all the classes that implement a Filter to include the name of the Filter. Suppose one then creates the following code segment after reading in earthquake data into the ArrayList of QuakeData called list.

6
MatchAllFilter maf = new MatchAllFilter();
maf.addFilter(new MagnitudeFilter(3.0,5.0,”Magnitude”));
Location city = new Location(51.7308,-34.1153);
maf.addFilter(new DistanceFromFilter(3000*1000, city, “Distance”));
maf.addFilter(new PhraseFilter(“any”, “i”, “Phrase”));
System.out.println(“Filters used are: ” + maf.getName());
There are no compile errors—the DistanceFromFilter class includes “implements Filter” in the first line of the class definition, the program runs and the output is:

Filters used are: Magnitude null Phrase

Which of the following is most likely the error as to why “null” was printed instead of Distance?

1 point

  • In the DistanceFromFilter class, a private variable for the name was not assigned the value of the parameter representing the name of the filter in the Constructor method.
  • The getName( ) method in the MatchAllFilter class had a logic error in it.
  • The filter method in the EarthQuakeClient2 class has a logic error.
  • There was not a getName( ) method in the DistanceFromFilter class.

Question 9: For the assignment you wrote the method quakesWithFilter in the class EarthQuakeClient2 to filter earthquakes using two criteria. Modify that criteria to be those that are 1,000,000 meters (1,000 km) from Denver, Colorado whose location is (39.7392, -104.9903), and that end with an ‘a’ in their title (for example, that might be an earthquake in Nevada as that ends in ‘a’). Run your program on the file nov20quakedata.atom (a file with information on 1518 quakes). You should also print out the number of such earthquakes found.

How many such earthquakes are there?

74

.
Question 10: For the assignment you wrote the method find Largest Quakes to print a given number of earthquakes from a data source in order from largest magnitude. Modify this method to run your program on the file nov20quakedata.atom (a file with information on 1518 quakes) for the 50 earthquakes with the largest magnitude.

What country had the 50th largest earthquake?

1 point

Solomon Islands

  • Greece
  • Kyrgyzstan
  • Indonesia
  • Japan

Question 11 : For the assignment you wrote the method test Match All Filter in the class Earth Quake Client 2 to filter earthquakes using three criteria. Modify that criteria to be those with magnitude between 1.0 and 4.0 inclusive, to test the depth between -180,000.0 and -30,000.0 inclusive, and if the letter “o” is in the title. Modify this method to run your program on the file nov quake data.atom (a file with information on 1518 quakes) with the same criteria. You should also print out the number of such earthquakes found.

How many such earthquakes are there?

1 point
Enter answer here

187


Question 12:- For the assignment you wrote the method test Match All Filter 2 in the class Earth Quake Client 2 to filter earthquakes using three criteria. Modify that criteria to be those with magnitude between 0.0 and 5.0 inclusive, to test for the distance from Bill and, Denmark at location (55.7308, 9.1153) is less than 3,000,000 meters (3000 km), and if the letter “e” is in the title. Run your program on the file nov 20 quake data.atom (a file with information on 1518 quakes) with the same criteria. You should also print out the number of such earthquakes found.

How many such earthquakes are there?

1 point
Enter answer here

17

Week- 2

Earthquakes: Sorting Algorithms


Question 1: For an assignment you wrote the method sort By Magnitude With Bubble Sort With Check in the class Quake Sort In Place to sort earthquakes by their magnitude from smallest to largest using the bubble sort algorithm, and stopping with passes once the ArrayList is sorted. Modify testSort to run this method on the file earth Quake Data WeekDec6sample2.atom. Make sure you are using the updated (1/12/16) version of the EarthQuakeParser class.

How many passes are needed to sort this file?

Note: This question has variations. If you attempt this quiz multiple times, make sure you are using the correct data file!

1 point

  • 1226
  • 1233
  • 1240
  • 1255
  • 1260
  • 1267

Question 2: For an assignment you wrote the method sort By Magnitude With Check in the class Quake Sort In Place to sort earthquakes by their magnitude from smallest to largest using the selection sort algorithm, and stopping with passes once the Array List is sorted. Modify test Sort to run this method on the file earth Quake Data WeekDec6sample1.atom.

How many passes are needed to sort this file?

Note: This question has variations. If you attempt this quiz multiple times, make sure you are using the correct data file!

1 point

  • 1282
  • 1292
  • 1298
  • 1299
  • 1301
  • 1319


Question 3: Consider an Array List of following six integers.

2 4 5 9 8 1
What does this Array List look like after two passes of selection sort that sorts the elements in numeric order from smallest to largest?

1 point

  • 1 2 4 9 8 5
  • 1 2 5 4 9 8
  • 1 2 5 9 8 4
  • 1 4 5 9 8 2
  • 2 4 5 9 8 1
  • 4 1 5 2 8 9

3. For an assignment you wrote the method sort By Magnitude With Bubble Sort With Check in the class Quake Sort In Place to sort earthquakes by their magnitude from smallest to largest using the bubble sort algorithm, and stopping with passes once the Array List is sorted. Modify test Sort to run this method on the file earth Quake DataWee Dec6sample1.atom.

How many passes are needed to sort this file?

Note: This question has variations. If you attempt this quiz multiple times, make sure you are using the correct data file!

1241


Question 4: For an assignment you wrote the method sort By Largest Depth in the class Quake Sort In Place to sort earthquakes by their depth from largest depth to smallest depth using the selection sort algorithm. Modify this method to do exactly 70 passes and then modify test Sort to run this method on the file earth Quake Data Dec6sample2.atom. The file may not be completely sorted as there are many quakes in the file.

Note: This question has variations. If you attempt this quiz multiple times, make sure you are using the correct number of sort passes!

1 point
Enter answer here

-100000.00

Question 5: Consider an Array List of following six integers.

4 2 5 9 8 1
What does this Array List look like after two passes of bubble sort that sorts the elements in numeric order from smallest to largest?

1 point

  • 2 4 1 5 8 9
  • 2 4 5 1 8 9
  • 2 4 5 8 1 9
  • 4 2 5 1 8 9
  • 4 2 5 8 1 9
  • 4 2 5 9 8 1


Question 6 :For an assignment, you wrote the Title And Depth Comparator to sort earthquakes by their title first, in alphabetical order, and to break ties by their depth, from smallest depth to largest depth. You then used the Collections.sort method with the Title And Depth Comparator. Modify the sort By Title And Depth method in the Different Sorters class to print out the Quake Entry in position 500 after sorting the Quake Entry’s by the above method. Run this method on the file earth Quake Data Week Dec6sample2.atom.

What is the depth of the earthquake that is in position 500 after the earthquakes are sorted by the above method?

Note: This question has variations. If you attempt this quiz multiple times, make sure you are using the correct data file!

1 point
Enter answer here

-7630.00


Question 7: For an assignment, you wrote the TitleLastAndMagnitudeComparator to sort earthquakes by the last word in their title first, in alphabetical order, and to break ties by their magnitude, from smallest to largest. You then used the Collections.sort method with the TitleLastAndMagnitudeComparator. Modify the sortByLastWordInTitleThenByMagnitude method in the DifferentSorters class to print out the QuakeEntry in position 500 after sorting the QuakeEntry’s by the above method. Run this method on the file earthQuakeDataWeekDec6sample2.atom

What is the depth of the earthquake that is in position 500 after the earthquakes are sorted by the above method?

Note: This question has variations. If you attempt this quiz multiple times, make sure you are using the correct data file!

1 point
Enter answer here

-1490.00


Question 8 : For an assignment, you modified the compare To operator in the class Quake Entry to sort earthquakes by their magnitude first, from smallest magnitude to largest magnitude, and to break ties by their depth, from largest depth to smallest depth. Then you wrote the method sort With Compare To in the Different Sorters class using the Collections.sort method. Modify this method to print out the Quake Entry in position 600 after sorting the Quake Entry’s by the above method. Run this method on the file earth Quake Data WeekDec6sample2.atom.

What is the depth of the earthquake that is in position 600 after the earthquakes are sorted by the above method?

Note: This question has variations. If you attempt this quiz multiple times, make sure you are using the correct data file!

1 point
Enter answer here

53600.00

Week- 3

N-Grams: Predictive Text


Question 1 : In the Markov Runner class in the run Markov Zero method, set the random seed to 1024 and run this method on the file confucius.txt.

What is the first line of text output when this program runs?

1 point
Enter answer here

eeuefmespwhsfoyu, s giowhersa eell: bma s.7shni:.at.ttdr.w aknf


Question 2 :Here is the code for runMarkovZero.

11
1 public void runMarkovZero() {
2 FileResource fr = new FileResource();
3 String st = fr.asString();
4 st = st.replace(‘\n’, ‘ ‘);
5 MarkovZero markov = new MarkovZero();
6 markov.setTraining(st);
7 for(int k=0; k < 3; k++) {
8 String text = markov.getRandomText(500);
9 printOut(text);
10 } Suppose the line markov.setRandom(18);
is put between lines 7 and 8, as the first line in the body of the for loop. Which one of the following options best describes how this line affects the program?

1 point

  • Each of three randomly generated texts will all be identical.
  • You will get three distinct randomly generated texts.
  • You will get three randomly generated texts, but the second generated text has one new letter and then is identical to the first text minus one letter, and the third generated text has one new letter and then is identical to the second text minus two letters.
  • You will get three randomly generated texts, but the second generated text has the first line with new random text, but the remaining lines are identical to the first n-1 lines where the first text had n lines. The third generated text has the first line with new random text, but the remaining lines are identical to the first n-1 lines of the second text.

Question 3 : In the Tester class, run the program testGetFollowsWithFile with the string “o” and the file confucius.txt.

What is the size of the ArrayList of characters that follow “o”?

1 point
Enter answer here

10453


Question 4 : In the Tester class, run the program testGetFollowsWithFile with the string “he” and the file confucius.txt.

What is the size of the ArrayList of characters that follow “he”?

1 point
Enter answer here

3715


Question 5 : After the completion of the MarkovModel class to generate random text by finding all the characters that follow N characters, set the random seed in the runMarkovModel method in the MarkovRunner class to 953 and pass in N as 7. Then run runMarkovModel on the file romeo.txt.

What is the first line of text generated?

1 point
Enter answer here

e uncle Capulet’s orchard. Enter an officer, and light- more

Question 6 : After the completion of the MarkovOne class to generate random text by finding all the characters that follow one character, set the random seed in the runMarkovOne method in the MarkovRunner class to 365. Then run runMarkovOne on the file romeo.txt.

What is the first line generated?

1 point
Enter answer here

y O wirs bloay Ger. fo. tifthy The, A My; st- ie d, s. bloulate,


Question 7: In the EfficientMarkovModel class, comment out the print statements in the printHashMapInfo method that prints out the map. Make sure printHashMapInfo is called right after the HashMap is built. Then in the MarkovRunnerWithInterface class call the runModel method on an EfficientMarkovModel of order 6 with seed 792 on the file confucius.txt.

How many keys are in the HashMap?

1 point
Enter answer here

Question 8 :In the EfficientMarkovModel class, comment out the print statements in the printHashMapInfo method that prints out the map. Make sure printHashMapInfo is called right after the HashMap is built. Then in the MarkovRunnerWithInterface class call the runModel method on an EfficientMarkovModel of order 5 with seed 531 on the file confucius.txt.

What was the size of the largest ArrayList in the HashMap?

1 point
Enter answer here

70162


Question 9 : For the class EfficientMarkovModel, which one of the following is the best place to call the buildMap method?

1 point

  • In the setTraining method.
  • In the constructor.
  • In the getRandomText method before the for loop.
  • In the getRandomText method as the first line in the for loop.
  • In the setRandomText method after myRandom is set.

In the EfficientMarkovModel class, comment out the print statements in the printHashMapInfo method that prints out the map. Make sure printHashMapInfo is called right after the HashMap is built. Then in the MarkovRunnerWithInterface class call the runModel method on an EfficientMarkovModel of order 5 with seed 531 on the file confucius.txt.

What was the size of the largest ArrayList in the HashMap?

1549

Question10: After the completion of the MarkovFour class to generate random text by finding all the characters that follow four characters, set the random seed in the runMarkovFour method in the MarkovRunner class to 715. Then run runMarkovFour on the file romeo.txt.

What is the first line of text generated?

1 point
Enter answer here

man in a green, for that haste, for a foot in her from Tybalt!

Week- 4

Java: Tools and Libraries for Everyone


Question 1 :What effect comes from declaring a field “static”?

1 point

  • The value in the field cannot be changed once it is initialized.
  • The value in the field can only be changed by code inside the class.
  • The value in the field can only increase, never decrease.
  • There is only one copy of that field for the entire class, not one per instance.


Question 2: What is the name of the method that starts a Java program

1 point

  • firstMethod
  • _start
  • main
  • begin

Question 3 : In Java, how is the keyword “throw” used?

1 point

  • To make an exception occur when the program detects a problematic circumstance that it cannot directly handle.
  • To transfer data across a network connection.
  • To handle an exception that has already occurred.
  • To open a file for writing.


Question 4 :What argument type should the method that starts a Java program take?

1 point

  • an int and a String
  • an ArrayList<String>
  • an array of Strings
  • no arguments

Question 5 : If you wanted to read the contents of a file without using the edu.duke package, you might call Files.newBufferedReader.

What would you pass into Files.newBufferedReader?

1 point

  • a Comparator
  • an IOException
  • a Path
  • a FileResource


Question 6 : In Java, how is the keyword “finally” used?

1 point

  • In exception handling to specify code that should be executed regardless of whether an exception happened or not.
  • To specify code to run when the program exits.
  • To specify a piece of code to execute immediately after the end of the current loop.
  • To indicate that you are finally done debugging a particularly complicated piece of code.


Question 7 : Creating a new socket, as with:

1
Socket s = new Socket(addr,port);
can throw an IOException according to the documentation of the java.net.Socket class.

Which of the following structures is the best way to create a socket while handling the exception?

1 point

try {
Socket s = new Socket(addr, port);
//code that uses s
}
catch(IOException ioe) {
//code to handle the exception
}

Question 8 : You saw that a BufferedReader can be used to read data from a file on the local computer, as well as from a website. You could also use it with other sources of data, as long as you have an appropriate Reader class to access the data.

These capabilities are a great example of the benefits of which programming principles? Select the two best options.

1 point

  • Open/Closed Principle: the BufferedReader class is designed such that it can have its functionality expanded (to read from new data sources) without having to modify its code
  • Everything Is A Number: the BufferedReader class can read data of any type, and return it as a Java object of an appropriate class
  • Abstraction: the BufferedReader class can work with any class that conforms to a specific interface, and does not need to know the details of how/where it reads data
  • Astrachan’s Law: you can only use the BufferedReader class to solve interesting problems, never for something boring or that you could do by hand
  • Write Robust Code: the BufferedReader class never throws an exception, instead it deals with every situation


Question 9 :If you need to read data from a website without using the edu.duke package, you would probably want to use classes found in which package?

1 point

  • java.internet
  • java.lolcats
  • java.net
  • java.urls

Conclusion:

Quizzes can be used to generate more interest among the students who want to learn in a competitive situation. Two such quizzes that work well with students in the middle school year level include “The Hollow Square Quiz” and “The Hollow Circle Quiz.” The second quiz is called “The Student Created Quiz”, which can be used as part of the revision program. From our website the student of each group will be get quiz answers on that topic.

Leave a Comment