These is the import line required to use ArrayLists.
What is...
import java.util.ArrayList;
?
In an ArrayList named "list", this is what you would write if you wanted to assign the length of the list to a new integer named "x".
What is...
int x = list.size()
This is the type of sort that you should use when your list is randomly organized (not mostly sorted).
What is...
Selection Sort
?
In a class "MyClass" with an instance variable "name", and a constructor that takes in another String name, this is how you would assign the parameter to the instance variable.
private String name;
public MyClass (String name)
{
~~~~Missing Code~~~~
}
This popular condiment was once sold as a medicinal cure for diarrhea.
What is...
ketchup?
This is what will print when you run the following:
ArrayList<String> list = new ArrayList<String>();
list.add("Computer");
list.add("Science");
System.out.println( list[1] );
What is...
Nothing will print! There will be a compiler error since an ArrayList does not use the [ ] notation.
?
list = [ 2, 4, 6, 8, 10 ]
This is printed after the following code executes:
int a = list.remove(2);
int b = list.remove(3);
int c = a + list.remove(2);
System.out.println( c / b );
What is...
1?
These are the FOUR standard values where the outer traversal for loops of Selection Sort begins and ends; and where the outer traversal for loops of Insertion Sort begins and ends.
Selection Sort:
for ( int index = ???; index< ??????; index++)
Insertion Sort:
for ( int index = ???; index< ??????; index++)
What is...
Selection Sort begins at 0, ends at size() -1
Insertion Sort begins at 1, ends at size()
?
This is the relationship between two objects, object1 and object2, when object1==object2 is true.
What is...
object1 and object2 refer to the SAME object at the same address (they are aliases of each other)
?
This is the candy that was originally known as "M&M's Fruit Chews".
What is...
Starburst?
This is the code to declare and instantiate an ArrayList of whole numbers named "weights".
What is...
ArrayList<Integer> weights = new ArrayList<Integer>()
list = [ "apple", "banana", "donut",]
What line of code would insert the String "cookie" into the correct alphabetical order?
What is...
list.add(2, "cookie");
?
These are the 3 main steps of Selection Sort (as psuedo code)
What is...
1. Traverse each index up to the second to last element
2. find the minimum in the rest of the list
3. swap the index and minIndex
?
According to DeMorgan's Law, this is the equivalent expression to !A || !B.
What is...
!( A && B )
?
The unicorn is the national animal of this country.
What is...
Scotland?
Choose all of the following that are valid ways to declare and instantiate an ArrayList:
a. ArrayList<String> list = new ArrayList<String>;
b. ArrayList<String> list = new ArrayList();
c. ArrayList<String> list = new ArrayList<String>();
d. Arraylist<String> list = new array[String];
The solution is both b and c. While not recommended, you CAN instantiate an ArrayList without a data type.
This is the ArrayList recipe after this code executes:
ArrayList <String> recipe = new ArrayList<String>();
recipe.add("bread");
recipe.add("cheese");
String food = "pizza";
recipe.add("ham");
food = recipe.remove(0);
recipe.add("apple");
recipe.add(food);
What is...
cheese, ham, apple, bread
?
These are the main steps of Insertion Sort (as psuedo code)
What is...
1. LOOP - Traverse each element starting from index 1
2. LOOP - Traverse sorted elements to the right to the left to find current element's position
3. Shift sorted elements to place current element
?
This is the line of code that will assign a random integer between 11 and 24, INCLUSIVE, to new integer range.
What is...
int range = (int) (Math.random() * 13) + 11;
?
According to Instacart, this is the most disliked food in America.
What are...
anchovies?
This is the printed output of the following code:
ArrayList<String> list = new ArrayList<String>();
list.add( "We" );
list.add( "love" );
list.add( "pizza" );
list.add( "from" );
list.add( "Villa Milano" );
list.remove(3);
System.out.println( list.get(3) );
What is...
"Villa Milano"
?
This is the missing line from the following search method to find the goal int from the given list:
public int search(ArrayList<Integer> list, int goal) {
for(int i = 0; i < list.size(); i++) {
***************
return i;
}
}
return -1;
}
What is...
if ( list.get(i) == goal ) {
?
This is the missing line of the below insertion sort:
public static int[] insertionSort(int [] arr) {
for (int i = 1; i < arr.length; i++) {
int curNumber = arr[i];
int curIndex = i -1;
while(curIndex>0&&arr[curIndex]>curNumber){
~~~~~missing line of code~~~~~
curIndex--;
}
}
return arr;
}
What is...
arr[curIndex + 1] = arr[curIndex];
?
For a bonus 100 points, what would the line be if we were working an ArrayList arr instead of array arr?
This is the code that uses an enhanced for loop to print out all the items from an array of Strings named "teams".
What is...
for (String team: teams)
{
System.out.println(team);
}
?
This was the first president to visit all 50 states.
Who is...
Richard Nixon?