CS111 Jeopardy Spring 2005 CS111 Jeopardy Spring ’05 – p.1/27
Gameboard Conditionals/ Worlds Bugs Lists Potpourri Recursion 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 CS111 Jeopardy Spring ’05 – p.2/27
Conditionals/Recursion 1 This is the part of a recursive method that guarantees the recursion will terminate. Back CS111 Jeopardy Spring ’05 – p.3/27
Conditionals/Recursion 2 This is the expression exp that makes the the single statement return exp ; equivalent to the following statement: if (b == false) { return true; } else { return false; } Back CS111 Jeopardy Spring ’05 – p.4/27
Conditionals/Recursion 3 This is the output of the following code snippet when x has the value 16 : if ((x > 5) && (x <= 15)) { System.out.println("Swiss Cheese"); } else { if ((x % 2)== 0) { System.out.println("American Cheese"); } else { System.out.println("Cheese Whiz"); } } Back CS111 Jeopardy Spring ’05 – p.5/27
Conditionals/Recursion 4 Given the recursive method below, this is the value of tunnel(10) . public static int tunnel (int n) { if (n<=1) { return 0; } else { return 1 + tunnel(n/2); } } Back CS111 Jeopardy Spring ’05 – p.6/27
Conditionals/Recursion 5 This is a Buggle method that will drop bagels all the way to the wall, which is an unknown distance away. Bagels are dropped in all cells in front of the Buggle, but not under the Buggle’s current cell. This method leaves position and heading invariant. Back CS111 Jeopardy Spring ’05 – p.7/27
Worlds 1 Buggles love to eat these. Back CS111 Jeopardy Spring ’05 – p.8/27
Worlds 2 Suppose that w is a PictureWorld picture of the wedge shown below in Figure 1. This is a PictureWorld expression that denotes the picture in Figure 2. Figure 1 Figure 2 Back CS111 Jeopardy Spring ’05 – p.9/27
Worlds 3 This is a definition of the buggle method satisfying the following contract: public void forwardTurningLeft(int n); Moves the buggle forward a total of n spaces, turning left whenever the buggle encounters a wall. (Turning does not count as “moving forward a space”.) Back CS111 Jeopardy Spring ’05 – p.10/27
Worlds 4 This is a definition of the buggle method satisfying the following contract: public boolean canGoForwardBy (int n); Returns true if the buggle would not encounter a wall in forward(n) , and false otherwise. Executing this method should leave the state of the buggle unchanged. Back CS111 Jeopardy Spring ’05 – p.11/27
Worlds 5 This is the picture drawn by invoking the turtle method pattern(40) on a new turtle, where pattern is defined as follows: public void pattern (int n) { if (n < 10) { fd(n) } else { pattern(n/2); lt(90); fd(n); bd(n); Back rt(90); pattern(n/2); }} CS111 Jeopardy Spring ’05 – p.12/27
Bugs 1 This is a bug in the following Buggle method: public void jello (int n) { if (n = 0) { dropBagel(); } else { forward(); jello(n - 1); backward(); } } Back CS111 Jeopardy Spring ’05 – p.13/27
Bugs 2 This is a bug in the following turtle method: public void crazy (int n) { if (n > 0) { fd(n); lt(45); crazy(n); rt(45); } } Back CS111 Jeopardy Spring ’05 – p.14/27
Bugs 3 This is a bug in the following Buggle method: public void dance (int n, Color c) { if ((n > 1) && !(isFacingWall())){ forward(); dance(c, n-2); backward(); } } Back CS111 Jeopardy Spring ’05 – p.15/27
Bugs 4 This is a bug in the following turtle method; public int spiral (int n) { if (n == 0) { return 0; } else { fd(n); lt(90); spiral(n/2); rt(90); bd(n); } } Back CS111 Jeopardy Spring ’05 – p.16/27
Bugs 5 This is the bug in the code below: public int eatBagels() { if (isFacingWall()) return 0; forward(); eatBagels(); int count = eatBagels(); if (isOverBagel()) { pickUpBagel(); backward(); return 1 + count; } else { backward(); return count; } } Back CS111 Jeopardy Spring ’05 – p.17/27
Lists 1 This is the shortest list. Back CS111 Jeopardy Spring ’05 – p.18/27
Lists 2 This is the length of the list StringListList.fromString("[[]]") Back CS111 Jeopardy Spring ’05 – p.19/27
Lists 3 This is the problem with this code: public static boolean isMem(String s, StringList l) { if (s.equals(head(l))) return true; else if (isEmpty(l)) return false; else /* not empty, not found */ return isMem(s, tail(l)); } Back CS111 Jeopardy Spring ’05 – p.20/27
Lists 4 This is the value of mystery(IntList.fromString("[1,47]")) where public static boolean mystery(IntList l) { return isEmpty(l)? true : (head(l)%2 == 1) && mystery(tail(l)); } Back CS111 Jeopardy Spring ’05 – p.21/27
Lists 5 These are the letters of the true expressions given: public boolean lucky7(IntList l) { if (isEmpty(l)) { return false; } else if (head(l) == 7) { return true; } else { return lucky7(tail(l)); } } a. lucky7(fromString("[1,3,5,7]")) b. lucky7(lucky7(fromString("[1,3,5,7]"))) c. lucky7(7) Back CS111 Jeopardy Spring ’05 – p.22/27
Potpourri 1 In the Java Execution Model, this is created when an instance method is invoked. Back CS111 Jeopardy Spring ’05 – p.23/27
Potpourri 2 This is the value of apple, after executing the three lines of code below: apple = 2; apple = apple + 2; apple = apple * -2; Back CS111 Jeopardy Spring ’05 – p.24/27
Potpourri 3 This is betty’s position after the following code has been executed: Buggle becky = new Buggle(); Buggle betty = becky; becky.forward(5); becky = new Buggle(); Back CS111 Jeopardy Spring ’05 – p.25/27
Potpourri 4 This is the value of the expression legal(methodB(4)) , given the two contracts: public int methodB (int n); Returns n multiplied by 5. public boolean legal(int n); Returns true if n is greater than or equal to 21 and false otherwise. Back CS111 Jeopardy Spring ’05 – p.26/27
Potpourri 5 This is what countBagels() returns for the following method definition given the configuration shown on the board. public int countBagels() { int n = 0; if (isFacingWall()) { return n; } else { forward(); if (isOverBagel()) { n = n + 1; } countBagels(); backward(); return n; } } Back CS111 Jeopardy Spring ’05 – p.27/27
Recommend
More recommend