1). int x = 0; // 0 int[] a = new int[4]; // 0-0-0-0 x = x + 1; // 1 mystery (x, a); int x = 1; // 1 x = x + 1; // 2 a[x] = a[x] + 1; // 0-0-1-0 Print "2 [0, 0, 1, 0]" Print "1 [0, 0, 1, 0]" x = x + 1; // 2 mystery (x, a); int x = 2; // 2 x = x + 1; // 3 a[x] = a[x] + 1; // 0-0-1-1 Print "3 [0, 0, 1, 1]" Print "2 [0, 0, 1, 1]" OUTPUT: 2 [0, 0, 1, 0] 1 [0, 0, 1, 0] 3 [0, 0, 1, 1] 2 [0, 0, 1, 1] 2). public static int countInRange (int[] arr, int min, int max) { // count will represent the number within the range int count = 0; for (int i = 0; i < arr.length; ++i) { // arr[I] is our current array element -- it should be within [min, max] if (min <= arr[i] && arr[i] <= max) { ++count; } } return count; } 3). public static boolean isSorted (int[] arr) { // IMPORTANT: start at index 1 instead of 0 for (int idx = 1; idx < arr.length; ++idx) { // ask if value to the left is greater than the value to the right if (arr[idx - 1] > arr[idx]) { // if it is, it is NOT sorted return false; } } // if we made it through the entire array, it's sorted return true; } 4). Procedural programming separates code by function rather than a logical grouping. OOP logically groups entities (state and member fields) with actionable behavior (methods). 5). Accessor -- provides a "view" on some information; nothing is changed; state is left alone Mutator -- modifies the state in some way 6). A simplified view of an object and it's required behaviors/representation. Only concerning ourselves with what is relevant. Hiding information we do not care about. Objects provide abstractions by defining a concrete representation of a state and behavior 7). public int quadrant() { if (x == 0 || y == 0) { return 0; } if (x > 0) { if (y > 0) { // x and y both positive return 1; } // x positive, y negative return 4; } else { if (y > 0) { // x negative, y positive return 2; } // x and y both negative return 3; } } 8). public int manhattanDistance(Point other) { // manhattan distance is defined as the change of x + the change of y // we MUST use Math.abs so it's positive int deltaX = Math.abs (x - other.x); int deltaY = Math.abs (y - other.y); return deltaX + deltaY; }