OC userin Computer Science·3 Jan 20183. Consider the following method, which returns the number of times the parameter String word occurs in the parameter array wordArray: public static int countOccurrences (String[] wordArray, String word) { int result; result = 0; for (int i = 0; i < wordArray.length; i++) { if (wordArray[i] == word) { result = result + 1; return result; Unfortunately, the above method contains a bug. This bug causes the method to return 0 instead of the expected value of 2 when it is called in the following code fragment: String[] animalism = { new String ("four"), new String ("legs"), new String ("good"), new String ("two"), new String ("legs"), new String ("bad") }; int count = count Occurrences (animalism, "legs"); System.out.println("Number of occurrences: " + count); Describe what the problem is, and suggest a simple way to fix it. BE BRIEF; overly long answers will be grounds for mark deductions.
OC userin Computer Science·3 Jan 201824. Consider the Insertion Sort (code 3) algorithm described in the appendix. How can we change this code to have the algorithm sort from largest to smallest instead? (A) Change line 9 to: a[j-1] = a[j]; (B) Change line 7 to: while(j >0 && a[j - 1] 0; i--) (E) Change line 12 to: a[i] = x;
OC userin Computer Science·31 Dec 201714. Consider the following method header: public static void method (double X, int y) Which of the following are valid ways to use this method? Write the letters corresponding to the correct answer(s) on your answer sheet. Note that there are five options total. Two are on the next page. (a) System.out.println (method (4,4)); (b) String s = "apple" method (Math.pow (2,3), s.length()); (c) double x=1.2; int y=7; method (double x, int y); (d) method (2.5, Math.sqrt (4)); (e) method (4, 4);
OC userin Computer Science·31 Dec 20173. 13 marks) Complete the body of a Scheme function named f to calculate 11x) = 1+1/2 x + 1/3.1.
OC userin Computer Science·29 Dec 201711. A _ is a temporary storage for recently accessed data; faster to access than main memory. a. cache b. thread c. hyper thread d. core
OC userin Computer Science·28 Dec 201723. What String does the following code return if the input to the method is the String with contents ABCD. public static String mystery (String input) { String tricky = ""; for (int i = 0; i < input.length(); i++) { tricky = input.charAt(input.length() - i - 1) + tricky; return tricky; (A) ABCD (B) DDCCBBAA (C) There is a runtime error. (D) AABBCCDD (E) DCBA
OC userin Computer Science·26 Dec 2017Question 12. [15 MARKS] In this question, you will develop two classes to keep track of airplanes and flights. Here is the header and docstring for class Airplane. class Airplane: Information about a particular airplane including the model, the serial number, the number of seats, and the number of miles travelled. Part (a) [2 MARKS] Complete method __init_for class Airplane. Note: you will most likely not need all of the space on this page. def __init__(self, plane_model, serial_num, num_seats, miles_travelled): (Airplane, str, str, int, float) Record the airplane's model plane_model, serial number serial_num, the number of seats, and the distance travelled miles_travelled. >>> airplane - Airplane('Boeing 747', '19643', 366, 45267.7) >>> airplane.model 'Boeing 747 >>> airplane serial 19643 >>> airplane. seats 366 >>> airplane.miles 45267.7
OC userin Computer Science·26 Dec 2017Part (c) (3 MARKS] Write an -_eq - method in class Airplane that compares two Airplane objects to see if they are equal. Consider two Airplanes equal if they have the same serial number. Follow the function design recipe, which includes writing a docstring.
OC userin Computer Science·27 Dec 201723. What does the following program print? void setup() { int x = 10; timesTwo (x); println(x); A. 10,20 B. 20, 10 C. 20,20 void timesTwo (int x) { x = x + 2; println(x);
OC userin Computer Science·25 Dec 201712. Random Access Memory (RAM) in a computer is said to be volatile, meaning: a) The content of memory is erased once the machine is turned off x b) The content of memory changes rapidly c) The content of memory changes unpredictably d) The content of memory cannot be read e) None of the above
OC userin Computer Science·27 Dec 201763. Line 4 (A) sum++; (B) sum+=sqSum; (C) sqSum+i; (D) sqSum+=2*i; (E) sum+=i;
OC userin Computer Science·23 Dec 201730. A major characteristic of private IP addresses is that they a. are not routable on the internet b. are classes addresses c. have the length of 64 bits d. do not require MAC physical addresses
OC userin Computer Science·24 Dec 201716. Select the best choice from the list of choices A-E above for what this program displays. for (int row = 0; row < height; row = row + 20){ rect(0, 0, width-row, height-row);
OC userin Computer Science·21 Dec 201725. The client-server model in a computer network describes a) The interaction between a human and a computer where services are provided by the computer in response to requests initiated by the human. b) The relationship of cooperating computers where the server component provides services to one or many clients which initiate requests for such services. X c) The interaction between a computer and a network switch. d) The interaction of between a computer and a network router. e) All of the above
OC userin Computer Science·22 Dec 201723. Consider again the array a = {5,7,1,4,1} and the Selection Sort (code 2) algorithm. What is the last value of the variable minPos, before the algorithm exits? (A) 0 (B) 4 (C) 2 (D) 5 (E) 1