Conditionals
Arrays, ArrayLists, and Hashmaps
Functions and Classes
String Concatenation
Officer Trivia
100

These are the three types of conditional statements.

What are "if", "else", and "else if" statements?

100

arr[i] = 23;

In the statement above, the variable "i" represents this.

What is an index?

100

This keyword will immediately stop the loop/function it is placed in and stores a value.

What is "return"?

100

This is the operator used for String concatenation.

What is + ?

100

This officer's favorite board game is Chinese checkers.

Who is Preksha?

200

These are the three logical operators (explain what each one does as well).

What are &&, ||, and !()?

&&(and) returns true only if the statement is true on either side of it.

|| (or) returns true if the statement on at least one side of it is true.

!() returns the opposite boolean value than the expression within the ().

200

This is the import statement written at the top of a file in order to use ArrayLists.

What is "import java.util.ArrayList;"?

200

Write a method to find the area of a square called "sq_Area" and takes in one int parameter, "side." The return type is also int. Call the method in the main method with the parameter "10."

What is "

public static void main(String[] args)
    {
       System.out.println("The area of a square with length 10 is " + sq_Area(10) + ".");
    }
   
    public static int sq_Area(int side){
        return side * side;
    }

"?


200

Find the error in the following print statement.

System.out.println("Hello, my name is", "Aiden.");

The comma should be replaced by a +.

200

This officer has hypermobile fingers.

Who is Atharva?

300

There is an error with the following method. What is it?

public static void main(String[] args)
    {
       for (int i = 0; i < 20; i += 4){
           if (i = 12){
               break;
           }
           System.out.println(i);
       }
    }

The () in the if statement should say i== 12 instead of i = 12.

300

How you would print out the contents of a 2D array defined below?

int[][] arr = new int[2][5];


for (int i = 0; i < 2; i++){
           for (int j = 0; j < 5; j++){
               System.out.println(arr[i][j]);
           }
       }

OR

for (int i = 0; i < 2; i++){
           for (int j = 0; j < 5; j++){
               System.out.print(arr[i][j] + " ");
           }
           System.out.println();
       }

The second option prints out the elements as in a grid format.

300

These are methods that can only be called after the creation of an object.

What are instance methods?

300

How would you incorporate the following variable into the following print statement?

int age = 7;

System.out.println("My brother is years old.");

System.out.println("My brother is " + age + " years old.");

300

This instructor can't swallow pills.

Who is Vanessa?

400

The following method prints if the a person's age makes them an adult or a minor. How can you fix it so it prints the correct statement for age 18 instead of printing nothing?

public static void Age(int user_age){
        if (user_age < 0){
            System.out.println("This is not a valid age.");
        }
        else if (user_age < 18){
            System.out.println("You are a minor.");
        }
        else if (user_age > 18){
            System.out.println("You are an adult.");
        }
    }

Change the condition for the second else if statement to (user_age >= 18).

400

This is how you would add the element "Alohomora" to index 3 of a String ArrayList called spells.

spells.add(3, "Alohomora");

400

Private variables as well as getter and setter functions are examples of this.

What is encapsulation?

400

What will this for loop print?

String word = "cat";
       for (int i = 0; i < 5; i++){
           word += "cat";
       }
       System.out.println(word);

What is "catcatcatcatcatcat"?

400

This officer is left-handed.

Who is Lilian?

500

int score = 53;
        if (score <= 25){
            System.out.println("Your score of " + score + " means you have a D.");
        }
        else if (score <= 50){
            System.out.println("Your score of " + score + " means you have a C.");
        }
        else if (score <= 75){
            System.out.println("Your score of " + score + " means you have a B.");
        }
        else if (score <= 100){
            System.out.println("Your score of " + score + " means you have an A.");
        }

This is the statement this code will return.

What is "Your score of 53 means that you have a B."?

500

Create a HashMap called students which stores key value pairs of ("Jamie", 11), ("Josh", 15), and ("Alexa", 13). Then remove the item with the key "Josh" from the HashMap and add another key value pair with your own name and age. Make sure to print out the original HashMap and then the final one!

import java.util.HashMap;
public class MyProgram
{
    public static void main(String[] args)
    {
        HashMap<String,Integer> students = new HashMap<>();
        students.put("Jaime", 11);
        students.put("Josh", 15);
        students.put("Alexa", 13);
        System.out.println(students);
       
        students.remove("Josh");
        students.put("You", 17);
        System.out.println(students);
    }
}

500

Write a parameterized constructor within a class called "Rocket" with instance variables called fuel (int), color (String), and height (int). Make sure to define the instance variables beforehand!

What is "

public class Rocket{
        private int fuel;
        private String color;
        private int height;
       
        public Rocket(int user_fuel, String user_color, int user_height){
            fuel = user_fuel;
            color = user_color;
            height = user_height;
        }
    }

"?

500

Write a program that allows the user to complete the following saying: "The pen is mightier than the."

import java.util.Scanner;
public class MyProgram
{  
    public static void main(String[] args)
    {
       Scanner scan = new Scanner(System.in);
       System.out.println("Please enter the word that completes the following phrase: The pen is mightier than the _____.");
       String word = scan.next();
       System.out.println("The pen is mightier than the " + word + ".");
    }
}

500

This officer's favorite mobile game is Brawl Stars.

Who is Adrian?

M
e
n
u