Units 1 - 3
Unit 4
Unit 5
Units 6, 7, 8
Units 9 & 10
100

This code checks if String "str1" is the same as String "str2".

Note: There are two possible answers. 

str1.equals(str2)

OR

str1.compareTo(str2) == 0

100

This code prints out the word "Hi" 125 times using a for loop.

for (int i = 0; i < 125; i++){
     System.out.println("Hi");
}

100

This code gives the header for a class named Cookie.

public class Cookie {

100

This code creates a new array named "words" that stores 12 Strings.

String[] words = new String[12];

100

This code gives the class header for a class called "Oatmeal" that is a subclass of "Cookie".

public class Oatmeal extends Cookie {

200

This code checks if the variable "num" is even.

num % 2 == 0
200

This code prints out the word "Hi" 125 times using a while loop.

int i = 0;
while (i < 125){
     System.out.println("Hi");
     i++;
}

200

This code creates an instance variable that is an integer called chips.

private int chips;

200

This code creates a new ArrayList called "nums" that will store integers.

ArrayList<Integer> nums = new ArrayList<Integer>();

200

This code is the constructor for class Oatmeal that takes one integer parameter and calls the superconstructor from class Cookie with that integer.

public Oatmeal(int c){
     super(c);
}

300

This code gets the letter at index "i" in the String "word".

word.substring(i, i+1)

300

This code creates a nested loop where the outer loop runs 5 times and the inner loop runs 6 times.

for (int i = 0; i < 5; i++) {
     for (int j = 0; j < 6; j++) {
          // do something
     }
}

300

This code is the constructor for class Cookie that takes an integer parameter and stores it in the instance variable "chips".

public Cookie(int c){
     chips = c;
}

300

This code adds together all the values in an array called nums. 

Note: There are two possible answers.

int total = 0;
for (int i = 0; i < nums.length; i++) {
     total += nums[i];
}
OR
for(int n : nums){
     total += n;
}

300

This code is in the Oatmeal class and calls the Cookie superclass's method "bake" with the argument "my oven". 

super.bake("my oven");

400

This code returns a random integer between int "MAX" and int "MIN".

(int) (Math.random() * (MAX-MIN+1) + MIN)

400

This code adds together all the digits in the integer "num".

int total = 0;
while (num > 0) {
     int digit = num % 10;
     total += digit;
     num /= 10;
}


400

This code is the method header for a method called "bake" that doesn't return anything and takes in a String parameter called "oven".

public void bake(String oven){
400

This code adds up all the values in a 2-dimensional array called "mat".

int total = 0;
for (int row = 0; row < mat.length; row++) {
    for (int col = 0; col < mat[row].length; col++){
        total += mat[row][col];
    }
}


400

This code is the toString method for the class Oatmeal that calls the superclass's toString method and adds the word "oatmeal".

public String toString(){
     return super.toString() + "oatmeal".
}

500

This is another way of writing
!A || !B.

(Hint: it uses &&)

A && B

500

This code removes all occurrences of the String "target" from the String "phrase".

while (phrase.indexOf(target) >= 0) {
    int i = phrase.indexOf(target);
    phrase = phrase.substring(0, i) + phrase.substring(i + target.length());
}


500

This code is the "getter" method for the integer instance variable chips.

public int getChips(){
     return chips;
}

500

This code finds and returns the index of String "target" within the array "words".

for (int i = 0; i < words.length; i++) {
    if (words[i] == target)
        return i;
}
return -1;


500

These are the two things required inside a non-infinite recursive method.

A base case and a recursive call to the same method.