Keeping it Class-y
Array of Sunshine
Feeling Loopy
Write it
Solve it
100

What are the methods that allow another class to view and change instance methods of a class

Accessor and Mutator Methods

100

How do you get the size of an array?

Use the .length function

100

What are the 3 loops that we have talked about so far?

While, for, enhanced for

100

Initialize a Painter object named bob that has an x position of 3, a y position of 5, is facing East and has 6 units of paint.

Painter bob = new Painter(3,5, "East", 6)

100

What is a result of the print statement?

int x = 10;

double y = 15.0;

System.out.println(x+y);

25.0

200

What is the role of a constructor?

When creating the objects, a constructor will set the instance variables for that object

200

Create an array of type string that holds the values

Have, a, Merry, Christmas

String[] something = {"Have", "a", "Merry","Christmas"}

200

What are the 3 parts to a for loop? Write and label them.

for(int i = 0; i < array.length; i++) {


}

Initialization, condition, change

200

Write the toString method for a class called Dog that uses the instance variables name and breed

ex. "Dog name: Air Bud, Breed: Lab"

public String toString() {

     return "Dog name: " + name + ", Breed: " + breed;

}

200

what are the values of arr after the following code is completed?

int[] arr = {1, 5, 8, 4};

arr[0] *= 2;

arr[1] = arr[0] + arr[3]

[2, 6, 8, 4]

300

What method is used to print an object? What is the act of adding this method to your class called?

toString Method

Overriding

300

How do you access an element at specified position? What is it called when you try to access an element at a position that doesn't exist in a list?

Using the index, array[index]

Out of bounds exception error

300

What are two reasons for using an enhanced for loop instead of a for loop or while loops when working with an array?

Readability and ease

Don't want to modify the array

Traversing through the entirety of an array

300

Write a parameterized constructor for the class Mystery that has instance variables x and y that are of type int.

public Mystery(int x, int y) {

     this.x = x;

     this.y = y;

}

300

int x = 2; int y = 0

while (x != 0) {

     x*= 4; y++;

     x%3 -1;

}

System.out.print(y);

2

400

What is a keyword used to set the visibility of classes, variables, constructors, and methods?

What is the name of the concept of hiding our instance variables from other classes using it?

Access modifier

Encapsulation

400
True or false, Arrays can change size after they are created?


Explain what to do if you want to change the size of an array



False. If you wanted change the size of an array, then you would need to create a new one and populate it with the values you want.

400

What is the error in the following code?

int[] array = {1, 3, 5, 8};

for (item : array) {

     array[item]++;

}

This will hit an out of bounds exception

400

Create two objects of the Painter class and save them in an array of Painter objects

Painter[] stuff = {new Painter(), new Painter()};

Painter bob = new Painter();

Painter lisa = new Painter();

Painter [] stuff = {bob, lisa};

400

What is printed out?

String[] arr = {"Hey", "Hello", "Goodbye"}

for(int i = 0; i < arr.length; i++) {

      for(int j = i+1; j<arr.length; j++) {

           System.out.println(arr[j - i]);

}}

Hello

Goodbye

Goodbye

500

public class Food {}

public class ItalianMenu extends Food {}

public class Pasta extends ItalianMenu


Use the idea of polymorphism to create an object of one class and store it in a different class

Food item = new ItalianMenu();

ItalianMenu item = new Pasta();

Food item = new Pasta();

500

What is the default value for Strings, ints, doubles and boolean when an an array is created but not given a value?

Null, 0, 0.0, false

500

Turn the while loop into a for loop

int count = 0;

while (count < 5) {

     System.out.println("Hello");

     count++;

}

for (int count = 0; count < 5; count++) {

     System.out.println("Hello);

}

500

Write a method in a Class called minimum that takes in an array of ints and returns the lowest value

public int minimum(int[] arr) {

     int temp = arr[0];

     for(num : arr) {

          if(num < temp) {

               temp = num;

          }

     )

)

500

What is printed out?

int[] nums = {2, 5, 7}

for (num : nums) {

     System.out.println(num / 2 + " " + num%2);

}

1 0

2 1

3 1