570 likes | 677 Views
JEOPARDY. CS: Chapter 2. If this, else that. Boolean. While (something Happens). For statements. Program Development. $100. $100. $100. $100. $100. $200. $200. $200. $200. $200. $300. $300. $300. $300. $300. $400. $400. $400. $400. $400. $500. $500. $500. $500.
E N D
JEOPARDY CS: Chapter 2
If this, else that Boolean While (something Happens) For statements Program Development $100 $100 $100 $100 $100 $200 $200 $200 $200 $200 $300 $300 $300 $300 $300 $400 $400 $400 $400 $400 $500 $500 $500 $500 $500
You have selected an area of the board not in play. OOPS! Click here to go back to the main board
ANSWER Program Development - $100 During program development, software requirements specify a) how the program will accomplish the task b) what the task is that the program must perform c) how to divide the task into subtasks d) how to test the program when it is done e) all of the above
ANSWER Program Development - $200 In which phase of program development would you expect the programmer(s) to determine the classes and objects needed? a) Software requirements b) Software design c) Software implementation d) Software testing e) Could occur in any of the above
ANSWER Program Development - $300 Which of the following would not be considered an algorithm? a) a recipe b) a computer program c) pseudocode d) a shopping list e) travel directions
ANSWER Program Development - $400 If a programmer follows the four phases of program development as intended, which of the four phases should require the least amount of creativity? a) Software requirements b) Software design c) Software implementation d) Software testing e) None of the above, all four levels would require equal creativity
ANSWER Program Development - $500 The idea that program instructions execute in order (linearly) unless otherwise specified through a conditional statement is known as a) boolean execution b) conditional statements c) try and catch d) sequentiality e) flow of control
ANSWER If this, else that - $100 if (a > 0) if (b < 0) x = x + 5; else if (a > 5) x = x + 4; else x = x + 3; else x = x + 2; If x is currently 0, a = 5 and b = 5, what will x become after the above statement is executed?
ANSWER If this, else that - $200 Consider the following code that will assign a letter grade of ‘A’, ‘B’, ‘C’, ‘D’, or ‘F’ depending on a student’s test score. if(score >= 90) grade = 'A'; if(score >= 80) grade = 'B'; if(score >= 70) grade = 'C'; if(score >= 60) grade = 'D'; else grade = ‘F’; a) This code will work correctly in all cases b) This code will work correctly only if grade >= 60 c) This code will work correctly only if grade < 60 d) This code will work correctly only if grade < 70 e) This code will not work correctly under any circumstances
ANSWER If this, else that - $300 Assume that x and y are int variables with x = 5, y = 3, and a and d are char variables with a = 'a' and d = 'A', and examine the following conditions: Condition 1: (x < y && x > 0) Condition 2: (a != d || x != 5) Condition 3: !(true && false) Condition 4: (x > y || a == 'A' || d != 'A') a) All 4 Conditions are true b) Only Condition 2 is true c) Condition 2 and Condition 4 are true only d) Conditions 2, 3 and 4 are all true, Condition 1 is not e) All 4 Conditions are false
ANSWER If this, else that - $400 If x is an int where x = 1, what will x be after the following loop terminates? while (x < 100) x *= 2; a) 2 b) 64 c) 100 d) 128 e) None of the above, this is an infinite loop
ANSWER If this, else that - $500 Consider the following outline of a nested if-else structure which has more if clauses than else clauses. Which of the statements below is true regarding this structure? if (condition1) if (condition2) statement1; else statement2; a) syntactically it is invalid to have more if clauses than else clauses b) statement2 will only execute if condition1 is false and condition2 is false c) statement2 will only execute if condition1 is true and condition2 is false d) statement2 will only execute if condition1 is false, it does not matter what condition2 is e) statement2 will never execute
ANSWER Boolean - $100 Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following? if (count != 0 && total / count > max) max = total / count; a) The condition short circuits and the assignment statement is not executed b) The condition short circuits and the assignment statement is executed without problem c) The condition does not short circuit causing a division by zero error d) The condition short circuits so that there is no division by zero error when evaluating the condition, but the assignment statement causes a division by zero error e) The condition will not compile because it uses improper syntax
ANSWER Boolean - $200 What is wrong, logically, with the following code? if (x > 10) System.out.println("Large"); else if (x > 6 && x <= 10) System.out.println("Medium"); else if (x > 3 && x <= 6) System.out.println("Small"); else System.out.println("Very small"); a) There is no logical error, but there is no need to have (x <= 10) in the second conditional or (x <= 6) in the third conditional b) There is no logical error, but there is no need to have (x > 6) in the second conditional or (x > 3) in the third conditional c) The logical error is that no matter what value x is, “Very small” is always printed out d) The logical error is that no matter what value x is, “Large” is always printed out e) There is nothing wrong with the logic at all
ANSWER Boolean - $300 Rewrite the following set of if statements using a nested if-else structure. if (score >= 90) grade = 'A'; if (score >= 80 && score < 90) grade = 'B'; if (score >= 70 && score < 80) grade = 'C'; if (score >= 60 && score < 70) grade = 'D'; if (score < 60) grade = 'F';
ANSWER Boolean - $400 A truth table shows, for the various true or false values of boolean variables, what the result of a boolean condition is. Fill in the following truth table. Assume that a, b and c are boolean variables. a b c a && (!b | | c) false false false false false true false true false False true true true false false true false true true true false true true true
ANSWER Boolean- $500 A truth table shows, for the various true or false values of boolean variables, what the result of a boolean condition is. Fill in the following truth table. Assume that a, b and c are boolean variables. a b c ! (a && b) | | ! (a && c) false false false False false true false true false false true true true false false true false true true true false true true true
ANSWER While (something Happens) - $100 If x is an int where x = 0, what will x be after the following loop terminates? while (x < 100) x *= 2; a) 2 a) 64 b) 100 c) 128 d) None of the above, this is an infinite loop
ANSWER While (something Happens) - $200 How many times will the following loop iterate? int x = 10; while (x > 0) { System.out.println(x); x--; } a) 0 times b) 1 time c) 9 times d) 10 times e) 11 times
ANSWER While (something Happens) - $300 A data verification loop is a loop that asks the user to input a value within a restricted range repeatedly until the user has input a value within the requested range. Write a data verification loop that that inputs an int value x within the range 0 and 100. Assume cs1.Keyboard has been imported.
ANSWER While (something Happens) - $400 Write a “query-controlled” loop that will continue to input int values from the user, adding each to the int value sum, and then ask if the user has another value to input, until the user says that there are no more values. Assume that cs1.Keyboard has been imported.
ANSWER While (something Happens) - $500 If x is an int where x = 1, what will x be after the following loop terminates? while (x < 100) x *= 2; a) 2 b) 64 c) 100 d) 128 e) None of the above, this is an infinite loop
ANSWER For statements - $100 Given the following code, where x = 0, what is the resulting value of x after the for-loop terminates? for(int i=0;i<5;i++) x += i; a) 0 b) 4 c) 5 d) 10 e) 15
ANSWER For statements - $200
ANSWER For statements - $300 The following nested loop structure will execute the inner most statement (x++) how many times? for(int j = 0; j < 100; j++) for(int k = 100; k > 0; k--) x++; a) 100 b) 200 c) 10,000 d) 20,000 e) 1,000,000
ANSWER For statements - $400 Show the output that would occur from the following code, including proper spacing. for(j = 0; j < 5; j++) { for(k = 0; k < 5; k++) if(j!=k) System.out.print(' '); else System.out.print('*'); System.out.println( ); }
ANSWER For statements - $500 How many times will the System.out.println(*); statement execute inside of the following nested for-loops? for(j=0; j<10; j++) for(k=10;k>j;k--) System.out.println("*");
DONE Program Development - $100 b. Explanation: The specification phase is to understand the problem at hand so that the programmer can determine what needs to be done to solve the problem. The other efforts listed above are part of the design phase (a, c) and testing phase (d).
DONE Program Development - $200 b. Explanation: Determining which classes and objects to use or create is part of the design.
DONE Program Development - $300 d. Explanation: An algorithm is a step-by-step description of how to solve a problem, written at some level of specificity. The recipe and probably the pseudocode are written at a “high level” whereas a program and perhaps travel directions are written in more detail. A shopping list is not a step-by-step description, so it would not qualify as an algorithm.
DONE Program Development - $400 c. Explanation: Once the implementation phase has been reached, the algorithm should have already been specified, so the only effort involved in the implementation phase is of translating from the design (which is probably in an English-like pseudocode) to the programming language, and entering the code through an editor. The requirements and design phases require understanding the problem and coming up with a solution respectively, requiring creativity, and the testing phase will require diagnostic abilities usually forcing the programmer(s) to becreative in how the errors are found and fixed.
DONE Program Development - $500 e. Explanation: The “flow of control” describes the order of execution of instructions. It defaults to being linear (or sequential) but is altered by using control statements like conditionals and loops.
DONE If this, else that - $100 Explanation: Since (a > 0) is true, the next condition is checked. Since (b < 0) is false, the else clause for this condition is executed. Since (a > 5) is false the else clause for this condition is executed, which is x = x + 3. Therefore, 3 is added to x, so it is now 3.
DONE If this, else that - $200 d. Explanation: The problem with this code is that it consists of three if statements followed by one if else statement, rather than a nested if-else statement. So the logic is improper
DONE If this, else that -$300 d. Explanation: Condition 1 is not true because (x < y) is false, making the entire condition false. Since (c != d) is true, Condition 2 is true even though (x != 5) is false. Condition 3 is true because (true && false) is false, but !false is true. Condition 4 is true because (x > y) is true, making the entire Condition true. Therefore, Conditions 2, 3 and 4 are true while Condition 1 is false.
DONE If this, else that - $400 d. Explanation: With x = 1, the loop condition is true and the statement executes, doubling x, which is now 2. Since the loop condition is still true, the statement executes again, doubling x to 4. The condition remains true for the next 4 iterations, where x becomes 8, 16, 32 and 64. Since (x < 100) is still true when x = 64, the loop iterates again and x becomes 2 * 64 = 128. Now, (x < 100) is no longer true and the loop terminates with x = 128.
DONE If this, else that - $500 b. Explanation: The else clause must be matched to the most recent if statement. Therefore, the else goes with the if statement that tests condition2, not the if statement that tests condition1. So, if condition1 is true and condition2 is false, then statement2 will execute.
DONE Boolean - $100 a. Explanation: Since count is 0, (count != 0) is false. Because the left-hand side of an && condition is false, the condition is short circuited, and so the right-hand side is not evaluated. Thus, a potential division by zero error is avoided. Because the condition is false, the statement max = total / count is not executed, again avoiding a potential division by zero error.
DONE Boolean - $200 • Explanation: Because this is a nested if-else statement, if (x > 10) is true, then the first println statement is executed and the rest of the statement is skipped. If (x > 10) is not true, then the first else clause is executed and the next if condition is tested. At this point, (x > 10) is known to be false and therefore (x <= 10) must be true, so there is no need to check this inequality. Similarly, if (x > 6) is false, then the second else clause is executed and the third if condition is tested. However, (x <= 6) must be true, so there is no need to check this inequality.
DONE Boolean - $300 if (score >= 90) grade = 'A'; else if (score >= 80) grade = 'B'; else if (score >= 70) grade = 'C'; else if (score >= 60) grade = 'D'; else grade = 'F';
DONE Boolean - $400 a b c a && (!b | | c) false false false false false false true false false true false false false true true false true false false true true false true true true true false false true true true true
DONE Boolean - $500 a b c ! (a && b) | | ! (a && c) false false false true false false true true false true false true false true true true true false false true true false true true true true false true true true true false
DONE While (something Happens) - $100 e. Explanation: Since x starts at 0, x *= 2; results in 0 * 2, or x = 0. Since x remains 0, (x < 100) remains true, and the loop repeats. x continues to be 0 and so the condition never changes to false, and thus the loop never terminates.
DONE While (something Happens) - $200 d. Explanation: Since the condition is tested before the loop body executes, the loop will not execute once x == 0. So, the loop iterates for x = 10, x = 9, …, x = 1, or 10 times.
DONE While (something Happens) - $300 int x; do { System.out.println("Enter an int value between 0 and 100"); x = Keyboard.readInt( ); } while (x >= 0 && x <= 100);
DONE While (something Happens) - $400 int x, sum = 0; String query; do { System.out.println("Enter an int value to be summed"); x = Keyboard.readInt( ); sum += x; System.out.println("Do you have any more ints to input? (Yes or No) "); query = Keyboard.readString( ); } while (query.equalsIgnoreCase("Yes"));
DONE While (something Happens) - $500 d. Explanation: With x = 1, the loop condition is true and the statement executes, doubling x, which is now 2. Since the loop condition is still true, the statement executes again, doubling x to 4. The condition remains true for the next 4 iterations, where x becomes 8, 16, 32 and 64. Since (x < 100) is still true when x = 64, the loop iterates again and x becomes 2 * 64 = 128. Now, (x < 100) is no longer true and the loop terminates with x = 128.
DONE For statements - $100 d. Explanation: Each pass through the for-loop results with the current value of the loop index, i, being added to x. The first time through the loop, i = 0 so x = x + 0 = 0. The second time through the loop i = 1 so x = x + 1 = 1. The third time through the loop i = 2 so x = x + 2 = 3. The fourth time through the loop i = 3 so x = x + 3 = 6. The fifth and final time through the loop i = 4 so x = x + 4 = 10.