1. A HashSet is a set that is similar to an ArrayList. A HashSet does not have any specific ordering. True or false?
Mark for Review (1) Points
True (*) False Correct 2. What is the output from the following code snippet? TreeSett=new TreeSet();
Mark for Review (1) Points
if (t.add("one")) if (t.add("two")) if (t.add ("three")) t.add("four"); for (String s : t) System.out.print (s); twofouronethree The code does not compiles. onetwothreefour fouronethreetwo (*) Incorrect. Refer to Section 6 Lesson 2. 3. What is the output from the following code snippet? Integer[] ar = {1, 2, 1, 3}; Set set = new TreeSet(Arrays.asList(ar)); set.add(4); for (Integer element : set) { System.out.print(element); }
Mark for Review (1) Points
1234 (*) 1213 12134 11234 Incorrect. Refer to Section 6 Lesson 2. 4. What is the correct definition of Enumeration (or enum)?
Mark for Review (1) Points
A bounded generic class Code that initializes an ArrayList A keyword that specifies a class whose objects are defined inside the class. (*) A list of elements that is dynamically stored. Incorrect. Refer to Section 6 Lesson 1. 5. < ? extends Animal > would only allow classes or subclasses of Animal to be used. True or False?
Mark for Review (1) Points
True (*) False Incorrect. Refer to Section 6 Lesson 1. 6. Enumerations (enums) must be declared in their own class. True or False?
Mark for Review (1) Points
True False (*) Incorrect. Refer to Section 6 Lesson 1. 7. Generic methods are required to be declared as static. True or False?
Mark for Review (1) Points
True False (*) Incorrect. Refer to Section 6 Lesson 1. 8. A LinkedList is a list of elements that is dynamically stored. True or false?
Mark for Review (1) Points
True (*) False Correct 9. Which scenario best describes a queue?
Mark for Review (1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. A row of books that you can take out of only the middle of the books first and work your way outward toward either edge. A line at the grocery store where the first person in the line is the first person to leave. (*) All of the above describe a queue. Correct 10. To allow our classes to have a natural order we could implement the Comparable interface.
Mark for Review
True or false?
(1) Points
True (*) False Incorrect. Refer to Section 6 Lesson 3. 11. Which of the following methods adds a Key-Value map to a HashMap?
Mark for Review (1) Points
put(Key, Value) (*) add(Key, Value) get(Key, Value) remove(Key, Value) Incorrect. Refer to Section 6 Lesson 3. 12. A sequential search is an iteration through the array that stops at the index where the desired element is found. True or false?
Mark for Review (1) Points
True (*) False Correct 13. Which searching algorithm involves using a low, middle, and high index value to find the location of a value in a sorted set of data (if it exists)?
Mark for Review (1) Points
Sequential Search Merge Sort Selection Sort Binary Search (*) All of the above Incorrect. Refer to Section 6 Lesson 4. 14. Which sort algorithm was used to sort the char array {'M', 'S', 'A', 'T', 'H'}? The steps are shown below: {'M', 'S', 'A', 'T', 'H'} {'M', 'A', 'S', 'T', 'H'} {'A', 'M', 'S', 'T', 'H'} {'A', 'M', 'S', 'H', 'T'} {'A', 'M', 'H', 'S', 'T'} {'A', 'H', 'M', 'S', 'T'} Binary Search Sequential Search Bubble Sort (*)
Mark for Review (1) Points
Selection Sort Merge Sort Incorrect. Refer to Section 6 Lesson 4. 15. Which of the following is the correct lexicographical order for the conents of the following int array?
Mark for Review (1) Points
{17, 1, 1, 83, 50, 28, 29, 3, 71, 22} {1, 2, 7, 0, 9, 5, 6, 4, 8, 3} {71, 1, 3, 28,29, 50, 22, 83, 1, 17} {83, 71, 50, 29, 28, 22, 17, 3, 1, 1} {1, 1, 3, 17, 22, 28, 29, 50, 71, 83} {1, 1, 17, 22, 28, 29, 3, 50, 71, 83} (*) 1. Which scenario best describes a queue?
Mark for Review (1) Points
A pile of pancakes with which you add some to the top and remove them one by one from the top to the bottom. A row of books that you can take out of only the middle of the books first and work your way outward toward either edge. A line at the grocery store where the first person in the line is the first person to leave. (*) All of the above describe a queue. Correct 2. FIFO stands for:
Mark for Review (1) Points
Fast Interface Fast Output Fast In Fast Out First In First Out (*) First Interface First Output Incorrect. Refer to Section 6 Lesson 3. 3. To allow our classes to have a natural order we could implement the Comparable interface. True or false?
Mark for Review (1) Points
True (*) False Correct 4. A HashMap can only store String types. True or false? True False (*)
Mark for Review (1) Points
Incorrect. Refer to Section 6 Lesson 3. 6. Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index, finding the next smallest value and swapping it into the next index and so on until the array is sorted. True or false?
Mark for Review (1) Points
True False (*) Incorrect. Refer to Section 6 Lesson 4. 7. Which of the following best describes lexicographical order?
Mark for Review (1) Points
The order of indicies after an array has been sorted. A simple sorting algorithm that is inefficient on large arrays. A complex sorting algorithm that is efficient on large arrays. An order based on the ASCII value of characters. (*) Incorrect. Refer to Section 6 Lesson 4. 8. Binary searches can be performed on sorted and unsorted data. True or false?
Mark for Review (1) Points
True False (*) Correct 9. Which one of the following would initialize a HashSet raffleTickets which will store the class RaffleTicket. HashSet raffleTickets = new HashSet(); (*) HashSet raffleTickets = new HashSet(); HashSet raffleTickets = new ();
Mark for Review (1) Points
HashSet raffleTickets = new HashSet(); Correct Which is the correct way to initialize a HashSet?
Mark for Review (1) Points
String classMates = new String(); classMates = new HashSet[String](); ClassMates = public class HashSet(); HashSet classMates = new HashSet(); (*) Correct 12. Enumerations (enums) are useful for storing data :
Mark for Review (1) Points
When you know all of the possibilities of the class (*) When the class is constantly changing You cannot store data in an enum. When the class is a subclass of Object. Incorrect. Refer to Section 6 Lesson 1. 13. What is the correct definition of Enumeration (or enum)?
Mark for Review (1) Points
A bounded generic class A keyword that specifies a class whose objects are defined inside the class. (*) A list of elements that is dynamically stored. Code that initializes an ArrayList Correct 14. Examine the code below. Which statement about this code is true? 1.class Shape { } 2.class Circle extends Shape { } 3.class Rectangle extends Shape { } 4.class Node { } 5.public class Test{ 6.public static void main(String[] args){ 7.Node nc = new Node<>(); 8.Node ns = nc; } } An error at line 8 causes compilation to fail. (*)
Mark for Review (1) Points
The code compiles. An error at line 4 causes compilation to fail. An error at line 7 causes compilation to fail. correct 15. Generic methods can only belong to generic classes. True or False?
Mark for Review (1) Points
True False (*) Incorrect. Refer to Section 6 Lesson 1. 1. Which searching algorithm involves using a low, middle, and high index value to find the location of a value in a sorted set of data (if it exists)?
Mark for Review (1) Points
Sequential Search Merge Sort Selection Sort Binary Search (*) All of the above Incorrect. Refer to Section 6 Lesson 4. 2. Bubble Sort is a sorting algorithm that involves swapping the smallest value into the first index, finding the next smallest value and swapping it into the next index and so on until the array is sorted. True or false?
Mark for Review (1) Points
True False (*) Correct 3. Why might a sequential search be inefficient?
It utilizes the "divide and conquer" method, which makes the algorithm more error prone. It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*) It involves looping through the array multiple times before finding the value, which is inefficient on large data sets.
Mark for Review (1) Points
It is never inefficient. Incorrect. Refer to Section 6 Lesson 4. 4. Which of the following sorting algorithms utilizes a "divide and conquer" technique to sort arrays with optimal speed?
Mark for Review (1) Points
Sequential Search Merge Sort (*) Selection Sort Binary Search All of the above Incorrect. Refer to Section 6 Lesson 4. 5. To allow our classes to have a natural order we could implement the Comparable interface. True or false?
Mark for Review (1) Points
True (*) False 6. Which statements, inserted it at line 2, will ensure that the code snippet will compile successfully.(Choose Two):
Mark for Review (1) Points
1.public static void main (String[]args) { 2,//insert code here 3. s.put ("StudentID", 123); 4.} (Choose all correct answers) ArrayList s= new ArrayList(); HashMap s= new HashMap(); (*) Map s= new SortedMap(); SortedMap s= new TreeMap(); (*) Incorrect. Refer to Section 6 Lesson 3. 7. The Comparable interface defines the compareTo method. True or false? True (*) False Incorrect. Refer to Section 6 Lesson 3.
Mark for Review (1) Points
8. FIFO stands for:
Mark for Review (1) Points
First In First Out (*) First Interface First Output Fast Interface Fast Output Fast In Fast Out Correct 9. The following code will compile. True or False? class Node implements Comparable{ public int compareTo(T obj){return 1;} } class Test{ public static void main(String[] args){ Node nc=new Node<>(); Comparable com=nc; } True (*) False Correct 11. The local petting zoo is writing a program to be able to collect group animals according to species to better keep track of what animals they have. Which of the following correctly defines a collection that may create these types of groupings for each species at the zoo?
Mark for Review (1) Points
Mark for Review (1) Points
public class animalCollection {ナ} (*) public class animalCollection(AnimalType T) {ナ} public class animalCollection {ナ} public class animalCollection(animalType) {ナ} None of the these. Correct 12. < ? extends Animal > would only allow classes or subclasses of Animal to be used. True or False?
Mark for Review (1) Points
True (*) False Correct 13. ArrayList and Arrays both require you to define their size before use. True or false?
Mark for Review (1) Points
True False (*) Incorrect. Refer to Section 6 Lesson 2. 14. Which of the following correctly adds "Cabbage" to the ArrayList vegetables?
Mark for Review (1) Points
vegetables.add("Cabbage"); (*) vegetables.get("Cabbage"); vegetables[0] = "Cabbage"; vegetables += "Cabbage"; Correct 1. A LinkedList is a list of elements that is dynamically stored. True or false?
Mark for Review (1) Points
True (*) False Correct 2. The Comparable interface defines the compareTo method. True or false? True (*) False
Mark for Review (1) Points
Correct 3. Implementing the Comparable interface in your class allows you to define its sort order. True or false?
Mark for Review (1) Points
True (*) False Correct 4. Which statements, inserted it at line 2, will ensure that the code snippet will compile successfully.(Choose Two): 1.public static void main (String[]args)
Mark for Review (1) Points
{
2,//insert code here 3. s.put ("StudentID", 123); 4.} (Choose all correct answers) HashMap s= new HashMap(); (*) SortedMap s= new TreeMap(); (*) ArrayList s= new ArrayList(); Map s= new SortedMap(); Incorrect. Refer to Section 6 Lesson 3. 6. Which code inserted into the code below guarantees that the program will output [1,2]? import java.util.*; public class Example{ public static void main(String[] args){ //insert code here set.add(2); set.add(1); System.out.println(set); } }
Mark for Review (1) Points
Set set = new SortedSet(); Set set = new TreeSet(); (*) Set set = new HashSet(); List set = new SortedList(); Set set = new LinkedHashSet(); Incorrect. Refer to Section 6 Lesson 2. 7. Which interface forms the root of the collections hierarchy?
java.util.Collection (*)
Mark for Review (1) Points
java.util.Map java.util.List java.util.Collections Incorrect. Refer to Section 6 Lesson 2. 8. The following code will compile. True or False?
Mark for Review (1) Points
class Node implements Comparable{ public int compareTo(T obj){return 1;} } class Test{ public static void main(String[] args){ Node nc=new Node<>(); Comparable com=nc; } True (*) False Correct 9. What is the correct definition of Enumeration (or enum)?
Mark for Review (1) Points
Code that initializes an ArrayList A list of elements that is dynamically stored. A bounded generic class A keyword that specifies a class whose objects are defined inside the class. (*) Correct 10. < ? extends Animal > would only allow classes or subclasses of Animal to be used. True or False? True (*) False Correct 11. < ? extends Animal > is an example of a bounded generic wildcard. True or False?
Mark for Review (1) Points
True (*) False
Mark for Review (1) Points
Incorrect. Refer to Section 6 Lesson 1. 12. Selection sort is a sorting algorithm that involves finding the minimum value in the list, swapping it with the value in the first position, and repeating these steps for the remainder of the list. True or false?
Mark for Review (1) Points
True (*) False Incorrect. Refer to Section 6 Lesson 4. 13. Why might a sequential search be inefficient?
Mark for Review (1) Points
It utilizes the "divide and conquer" method, which makes the algorithm more error prone. It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*) It involves looping through the array multiple times before finding the value, which is inefficient on large data sets. It is never inefficient. Correct 14. Why might a sequential search be inefficient?
Mark for Review (1) Points
It utilizes the "divide and conquer" method, which makes the algorithm more error prone. It requires incrementing through the entire array in the worst case, which is inefficient on large data sets. (*) It involves looping through the array multiple times before finding the value, which is inefficient on large data sets. It is never inefficient. Incorrect. Refer to Section 6 Lesson 4. 15. Big-O Notation is used in Computer Science to describe the performance of Sorts and Searches on arrays. True or false? True (*) False Incorrect. Refer to Section 6 Lesson 4.
Mark for Review (1) Points