OC userin Computer Science·16 Apr 201841. The eat method should go through the cookie jar, find the first cookie of the type given as input and take it out of the jar. It should then return the number of calories of that cookie, or 0 if no cookie of that type is in the jar. What is the correct line of code to be added at line 31? (A) Nothing is missing (B) for (int i = 0; i < cookies.size(); i++) (C) while (cookies.size() > 0) (D) for (int i = 1; i <= cookies.size(); i++) (E) if (cookies.getType (type))
OC userin Computer Science·13 Apr 2018Type of Errors For each of the following answer whether they would cause an compiler error, runtime error, or a bug. In other cases the mentioned error may not cause a problem for the computer and is merely a question of style. In this case you should choose "Style" In other cases the question may not cause a problem at all in which case you should answer "No Error" For the purpose of this question, you can use the following definitions: • Compiler error : An error that occurs during the compilation phase of your development. In this case no class file is produced. • Runtime error: An error that occurs while you are running your program. Your program starts to execute but terminates before the main method has finished executing. • Logical error or bug : An error that results in the wrong results being seen • Style error: The error does not make a difference to the computer but is something that may be considered bad code. 7. Omitting a semi-colon at the end of a variable assignment. (A) Compiler Error (B) Bug (logical) Error (C) Style (D) Runtime Error (E) No Error
OC userin Computer Science·14 Apr 201859. Line 7 (A) System.out.print("null"); } } (B) System.out.print("*"); } } (C) System.out.print("\n"); } } (D) System.out.print(""); } } (E) System.out.print(" "); } } Coding Question - Sum square difference Write a method called sumSqDiff that takes an input an integer upperBound and returns the difference between the square of the sum and the sum of the squares of all natural numbers, up to and including that bound. For example, if the upperBound is 10, your method should compute the following: 102 (1) (1+2+3+...+10)2 – (12 +22 +32 +...+102) Use the 6 following questions to "write" your code. Pay close attention to how your answers group together with each other.
OC userin Computer Science·11 Apr 20184. Consider the following code: What prints when it is executed? public class MidtermExamples public static void main(String[] args) { int x = 10; int y = 20; y = confusing (y,x); System.out.print (x + " " + y + " "); public static int confusing (int x, int y){ int temp = Y; y = x; X = temp; System.out.print (x + " " + y + " "); return x;
OC userin Computer Science·9 Apr 201822. Recall that virtualization allows a guest operating system (OS) to run on a virtual machine inside a host operating system. Which of the following statements is true? a) Applications running on a virtual machine do experience performance degradation compared to running on a real machine. x b) A virtual machine typically lacks the functionalities of a real machine. c) A virtual machine cannot run multiple applications simultaneously i.e. do multitasking). d) A virtual machine does not need RAM to run. e) None of the above
OC userin Computer Science·6 Apr 201830. What expression goes in the blank so this program draws a red ball when the mouse is pressed and a black ball otherwise? void draw() { A. mouse Pressed == true background (255); B. mouse Pressed drawBall (mousex, mousey, C. both A and B work D. !mousePressed E mouse Pressed == false void drawBall(int x, int y, boolean red) { if (red) { fill(255,0,0); else { fili(0); ellipse(x, y, 40, 40);
OC userin Computer Science·5 Apr 201843. The bake method should create the number of cookies of the type and calorie as given and then add them to the cookie jar on which the method was called. Which of the below is the correct method body given that the input parameters are named type, number and calPerCookie? (A) for (int i = 0; i < number; i++) cookies.add(new Cookie ()); (B) for (int i = 0; i < number; i++) cookies.add(new Cookie (type, calperCookie)); (C) cookies.add(number * new Cookie (type, calperCookie); (D) Cookie c = new Cookie (type, calperCookie) cookies. add (number * c); (E) addCookies (type, number, calPerCookie);
OC userin Computer Science·5 Apr 20186. Which image is drawn by the following program? translate (50, 50); rotate (radians (45)); line (-100,0,100,0); sketo translate(25, 0); rect(0,0,40, 20); skete skete... sketc... sketc...
OC userin Computer Science·7 Apr 201821. Which image is the result of the following program? void setup() { for (int y=0; y<100; y=y+10) { for (int x=width-y-10; x<100; x=x +10) { rect (x, y, 10, 10); B DE NIITIT DITU UTII LUU
OC userin Computer Science·5 Apr 2018• Given an int[] array of size 3, write a boolean expression indicating whether exactly 2 values in the array are even.
OC userin Computer Science·6 Apr 201813. The Fetch-Decode-Execute cycle refers to the process by which the CPU a) Retrieves a program instruction from the main memory, determines the action dictated by the instruction, and carries out the action. X b) Retrieves a program instruction from permanent storage and places it in the main memory. c) Retrieves data for a program and places it in the accumulator. d) Fetches the user input and displays it on the screen. e) None of the above
OC userin Computer Science·3 Apr 2018Part (b) [1 MARK] Instead of representing the mapping as a list of str, representing it as which of the following types would make implementing this function easier? (circle one) (a) list of list of str (b) dict of {int: str} (c) dict of str: int}
OC userin Computer Science·3 Apr 201841. A variable of type char can be used to store text such as HelloWorld! (A) FALSE (B) TRUE
OC userin Computer Science·2 Apr 2018void setup() { f2(f3(4)); 26. What is the last number printed by the program to the right? A. 4 B. 12 c. 14 D. 16 E. 18 void fl(int x){ println("fl " + x); void f2(int x) { println("x is " + x); fl(x+2); int f3(int x) { println("f3 " + x); return x+10;