Look at the Strings section of the handout. What term describes the relationship between str1 and str3.
aliases
What is the contents of the ArrayList nums after all lines of code have run on the handout?
10, 20, 30, 10
A class that converts primitive data types into objects.
Wrapper Class
Type out the correct statement that will initialize an array of Strings called "words" with four empty spaces.
String[] words = new String[4];
str1.substring(10);
"igh School"
What term is used to describe when a class has more than one constructor, each one with a different signature?
Overloading
Look at Example 1. What will print if the initial value of num is 10?
10 20
Changing a variable from one type to another
Type Casting
What is the result of the following code
ArrayList<String> laundry = new ArrayList<String>();
laundry.add("shirt");
laundry.add("sock");
laundry.add("sock");
laundry.add("sweater");
laundry.add("shorts");
laundry.remove(1);
System.out.print(laundry)
[shirt, sock, sweater, shorts]
str2.substring(4,8);
" of "
What term describes the ability of multiple objects of a superclass and subclass to be stored in an ArrayList of superclass objects, then have the same method called on each object to observe its unique behavior?
Polymorphism
Look at Example 1. How many times will the "else" code execute if the initial value of num is 2?
Three times
Write the call to Math.random() to pick a random number between 50 and 100.
(int)(Math.random() * 51) + 50
An array of int values called arr was initialized with elements {3, 1, 7, 3, 0} After 3 iterations of the selection sort, what is the status of the array?
{0, 1, 3, 7, 3}
str3.indexOf("a");
1
Name two of the three sorting algorithms that we learned in 2nd semester. Bonus 200 if you name all three.
Selection, Insertion, and Merge sorts
Look at Example 2. Fill in the missing code for the APStudent class's constructor.
super(name, IDNum);
this.apExams = apExams;
Information provided in a multi-line comment before a method that describes what must be true BEFORE the method runs.
Bonus 100 if you name what must be true AFTER the method runs.
Preconditions
Postconditions
An array of String objects is created and initialized as {"Nobody", "Time", "Element", "Cow", "Apple"}. After two iterations of the insertion sort, what is the state of the array?
{"Element", "Nobody", "Time", "Cow", "Apple"}
str1.substring(2,3) + str2.substring(12);
"kEagles"
Vocab term that describes a variable whose value is intended to be constant. These are identified by using ALL CAPS when naming the variable.
Final
Write an enhanced for loop that will print all of the values in either myInts or values.
for(int num: myInts) {
System.out.println(num);
}
for(double value: values) {
System.out.println(value);
}
What is the syntax to create a multi-line comment?
/*
*/
Suppose an array of type 'int' is to be sorted in decreasing order using the selection sort algorithm. If the array is originally {2, 8, 10, 6, 5, 13}, what will the array look like after 2 passes of the sorting loop?
{13, 10, 8, 6, 5, 2}
str1.substring(14) + str4.substring(4,6);
"Schoolla"