20. wordList is type ListInterface<String>.
What is printed?
wordList.add("car"); wordList.add("boat"); wordList.add("plane"); System.out.println(wordList.replace(2, "train"));
none of these is correct |
2 |
false |
true |
car |
train |
you cannot tell from the provided code |
boat |
plane |
null |
Question 21
wordList is type ListInterface<String>.
What is printed?
wordList.add("car"); wordList.add("boat"); wordList.add("plane"); System.out.println(wordList.replace(4, "train"));
train |
plane |
null |
none of these is correct |
car |
true |
false |
an exception will be thrown |
boat |
you cannot tell from the provided code |
22. wordList is type ListInterface<String>.
What is printed?
wordList.add("sun"); wordList.add("tree"); wordList.add("bird"); wordList.add("ocean"); System.out.println(wordList.contains("bird"));
1 |
an exception will be thrown |
null |
0 |
false |
4 |
true |
3 |
you cannot tell from the provided code |
2 |
none of these is correct |
Question 23
wordList is type ListInterface<String>.
What is printed?
wordList.add("sun"); wordList.add("tree"); wordList.add("bird"); wordList.add("ocean"); System.out.println(wordList.contains("snow"));
true |
-1 |
null |
you cannot tell from the provided code |
0 |
an exception will be thrown |
false |
none of these is correct |
Question 24
wordList is type ListInterface<String>.
What is printed?
wordList.add("car"); wordList.add("boat"); wordList.add("plane"); wordList.clear(); System.out.println(wordList.isEmpty());
3 |
2 |
0 |
1 |
you cannot tell from the provided code |
an exception will be thrown |
true |
null |
false |
none of these is correct |
Question 25
What is true about the code below? wordList is type ListInterface<String>.
wordList.add("sun"); wordList.add("tree"); wordList.add("bird"); wordList.add("ocean"); for(int i=0; i<wordList.getLength(); i++) { System.out.println(wordList.getEntry(i)); }
there will be a compiler error |
there are no errors |
there will be a runtime error (an exception thrown) |
Question 26
What is true about the code below? wordList is type ListInterface<String>.
wordList.add("sun"); wordList.add("tree"); wordList.add("bird"); wordList.add("ocean"); for(String word : wordList) { System.out.println(word); }
there are no errors |
there will be a runtime error (an exception thrown) |
there will be a compiler error |
Question 27
When the code completes, the list is empty. wordList is type ListInterface<String>.
wordList.add("apple"); wordList.add("banana"); wordList.add("carrot"); ... more adds (not shown) wordList.add("watermelon"); for(int i=1; i<=wordList.getLength(); i++) { wordList.remove(i); }
True |
False |
Flag this Question
These next set of questions ask about objects of type List (in the Java standard library).
Refer to the API page (Links to an external site.)Links to an external site. for details.
Remember that List objects start at position 0! Carefully review the API to see how the List methods work.
Question 28
What is true about the code below? wordList is type List<String>.
wordList.add("sun"); wordList.add("tree"); wordList.add("bird"); wordList.add("ocean"); for(int i=0; i<wordList.size(); i++) { System.out.println(wordList.get(i)); }
there will be a runtime error (an exception thrown) |
there are no errors |
there will be a compiler error |
Question 29
wordList is type List<String>.
What is printed?
wordList.add("apple"); wordList.add("banana"); wordList.add("cat"); wordList.add(2, "dog"); System.out.println(wordList.size());
none of these is correct |
you cannot tell from the provided code |
4 |
2 |
0 |
3 |
5 |
1 |
Question 30
wordList is type List<String>.
What is printed?
wordList.add("apple"); wordList.add("banana"); wordList.add("cat"); wordList.add(2, "dog"); System.out.println(wordList.get(3));
banana |
apple |
cat |
you cannot tell from the provided code |
null |
none of these is correct |
an exception will be thrown |
dog |
Question 31
wordList is type List<String>.
What is printed?
wordList.add("apple"); wordList.add("banana"); wordList.add("cat"); wordList.add("dog"); System.out.println(wordList.get(4));
apple |
null |
true |
cat |
banana |
an exception will be thrown |
you cannot tell from the provided code |
false |
dog |
33. wordList is type List<String>.
What is printed?
wordList.add("house"); wordList.add("yard"); wordList.add("car"); wordList.add("street"); System.out.println(wordList.remove(2));
you cannot tell from the provided code |
yard |
false |
null |
none of these is correct |
true |
an exception will be thrown |
house |
street |
car |
Question 34
wordList is type List<String>.
What is printed?
wordList.add("house"); wordList.add("yard"); wordList.add("car"); wordList.add("street"); System.out.println(wordList.remove(6));
false |
none of these is correct |
you cannot tell from the provided code |
street |
car |
house |
null |
yard |
an exception will be thrown |
true |
Question 35
wordList is type List<String>.
What is printed?
wordList.add("car"); wordList.add("boat"); wordList.add("plane"); System.out.println(wordList.set(2, "train"));
2 |
boat |
false |
true |
car |
plane |
an exception will be thrown |
none of these is correct |
null |
you cannot tell from the provided code |
train |
Question 36
wordList is type List<String>.
What is printed?
wordList.add("car"); wordList.add("boat"); wordList.add("plane"); System.out.println(wordList.set(6, "train"));
train |
none of these is correct |
plane |
true |
car |
false |
boat |
null |
an exception will be thrown |
you cannot tell from the provided code |
Question 37
When the code completes, the list is empty. wordList is type List<String>.
wordList.add("apple"); wordList.add("banana"); wordList.add("carrot"); ... more adds (not shown) wordList.add("watermelon"); for(int i=0; i<wordList.size(); i++) { wordList.remove(i); }
True |
False |
Question 38
What is true about the code below? wordList is type List<String>.
wordList.add("sun"); wordList.add("tree"); wordList.add("bird"); wordList.add("ocean"); for(String word : wordList) { System.out.println(word); }
there are no errors |
there will be a runtime error (an exception thrown) |
there will be a compiler error |
Question 35
wordList is type List<String>.
What is printed?
wordList.add("car"); wordList.add("boat"); wordList.add("plane"); System.out.println(wordList.set(2, "train"));
Answer: none of these is correct
Explanation: The statement wordList.set(2, "train") replaces the element at the 2nd index with "train", but it does not print anything.
Question 36
wordList is type List<String>.
What is printed?
wordList.add("car"); wordList.add("boat"); wordList.add("plane"); System.out.println(wordList.set(6, "train"));
Answer: an exception will be thrown
Explanation: Clearly, the size of wordList is 2, and hence, setting the element at 6th index will throw an IndexOutOfBoundException.
Question 37
When the code completes, the list is empty. wordList is type List<String>.
wordList.add("apple"); wordList.add("banana"); wordList.add("carrot"); ... more adds (not shown) wordList.add("watermelon"); for(int i=0; i<wordList.size(); i++) { wordList.remove(i); }
Answer: True
Explanation: The statement wordList.remove(i) will remove the element at index 'i' and because of the for loop, all the elements of the wordList are removed.
Question 38
What is true about the code below? wordList is type List<String>.
wordList.add("sun"); wordList.add("tree"); wordList.add("bird"); wordList.add("ocean"); for(String word : wordList) { System.out.println(word); }
Answer: there are no errors
Explanation: this piece of code prints all the elements of the wordList in new line.
NOTE: As per Chegg policy, I am allowed to answer only 4 questions (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.
20. wordList is type ListInterface<String>. What is printed? wordList.add("car"); wordList.add("boat"); wordList.add("plane"); System.out.println(wordList.replace(2, "train")); none of these...
Consider java for fixing this code please: what i need is to insert method to be added ( please don't change the test class and any giving value in the first class ) here is the correct out put: ------------------testAddLast()---- {A} {A->B} {A->B->null} {A->B->null->C} ----------------------------- --------testSubListOfSmallerValues()---------- {} {B->B->B->A} {F->B->B->B->A->D} {F->B->B->G->B->A->M->D} ----------------------------- ------------Test lastIndexOf()----- -1 3 -1 -1 0 5 2 ----------------------------- ---------testRetainAll()--------- {} {6:Tony->6:Tony} {null->bad->null} ----------------------------- ---------------Test removeStartingAtBack--- false true {apple->null->bad->null} true {apple->null->bad} {2:Morning->3:Abby->4:Tim->5:Tom->6:Tony} ----------------------------- ---------test insertionSort()--------- {} {D} {D->E->E->F->G}...
Using Python. 3) Create a single-linked list (StudentList) where the data in the link is an object of type pointer to Student as defined below. Note that you need to store and pass a pointer of type Student so that you do not create duplicate objects. Test your list with the provided program. You will find example code for a single-linked list of integers in Moodle that you can base your solution on. For your find methods, you can either...
A Chinese restaurant wants to have a computer-based search system that will display a recipe for each dish. The owner of the restaurant wants the system to be flexible in that its recipes are stored in a text file. This way, the number of dishes can be expanded by adding more entries to the text file without changing any program code. After analyzing the coding the restaurant realizes that Current coding only outputs first two line of the recipe. Goal:...
Need help doing program In bold is problem E2 #include<iostream> #include<string> #include<vector> using namespace std; //Car class //Defined enum here enum Kind{business,maintenance,other,box,tank,flat,otherFreight,chair,seater,otherPassenger}; //Defined array of strings string KIND_ARRAY[]={"business","maintenance","other,box","tank,flat","otherFreight","chair","seater","otherPassenger"}; class Car { private: string reportingMark; int carNumber; Kind kind; //changed to Kind bool loaded; string destination; public: //Defined setKind function Kind setKind(string knd) { for(int i=0;i<8;i++) //repeat upto 8 kinds { if(knd.compare(KIND_ARRAY[i])==0) //if matched in Array kind=(Kind)i; //setup that kind } return kind; } //Default constructor Car() { } //Parameterized constructor...
Your teacher is going to give a test where each student is to answer one question. None of the neighboring students should have the same question. How many questions are needed? Graph Coloring Algorithm is used to solve this type of problems. It does not guarantee to use the minimum number of questions, but it guarantees an upper bound on the number of questions. The algorithm never uses more than d+1 questions where d is the maximum degree of vertices...
Original question: I need a program that simulates a flower pack with the traits listed below: - You must use a LinkedList for storage (not an Arrray list). - You must be able to display, add, remove, sort, filter, and analyze information from our flower pack. - The flower pack should hold flowers, weeds, fungus, and herbs. All should be a subclass of a plant class. - Each subclass shares certain qualities (ID, Name, and Color) – plant class -...
True False Question 2 (3 points) Given a singly linked list with more than two nodes, to remove the second node from a linked list with only head reference, assume curr - head, next, you do Set curr.next to head.next Oset head. next to curr.next Set head, next to curr Oset head to curr.next TL th Question 3 (3 points) Given the following singly linked list (a list with four nodes), what will be the value stored at the last...
starter code To write a program using the starter code which is TestLinkedList to see if the LinkedList program has bugs. It will produce ether a pass or fail.More information is in the first two pictures. LinkedList.java /** * @author someone * * Implements a double-linked list with four errors */ public class LinkedList<E> { // The first and last nodes in the list private Node<E> head, tail; // Number of items stored in the list private int size; //...
please help!!!! JAVA I done the project expect one part but I still give you all the detail that you needed... and I will post my code please help me fix the CreateGrid() part in main and make GUI works List Type Data Structures Overview : You will be implementing my version of a linked list. This is a linked list which has possible sublists descending from each node. These sublists are used to group together all nodes which...
You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...