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;
OC userin Computer Science·3 Apr 201865. Line 6 (A) result = sum - sqSum; } (B) result = sum-sum - sqSum; } (C) return sum*sum - sqSum; } (D) return sum*sum + sqSum; } (E) return = sqSum - sum-sum; }
OC userin Computer Science·1 Apr 201818. Recall that in a Round Robin CPU scheduling each process takes turn and runs for a specified time slice. Assume 3 processes are in ready states with required service times in seconds) as indicated in the following table. Assume also that allowed time slice is 10 seconds. What is the turn-around time for process P2? Process Service Time P1 25 P2 30 To a) 30 b) 55 c) 75 x d) 100 e) None of the above
OC userin Computer Science·31 Mar 201834. 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);
OC userin Computer Science·28 Mar 201835. What does the following program print? int( data = {10,20,30,40,50); for (int i = data.length-2; i >= 0; i--) { data[i+1] = data[i]; for (int i = 0; i < data.length; i++) { print (data[i] + " "); A. 10 20 30 40 50 B. 50 40 30 20 10 C. 10 10 20 30 40 D. 20 30 40 50 50 E 10 20 20 30 40
OC userin Computer Science·28 Mar 20181. In one or two sentences, explain each of the following concepts. BE BRIEF; overly long answers will be grounds for mark deductions. (a) Off-by-one error
OC userin Computer Science·27 Mar 201820. What are the elements referred to by the variable a after the following code executes? public static void main(String[] args) { int[] a = {1,2,3,4,5,6); mystery (a); public static void mystery (int[] a) { for (int i=0; i
OC userin Computer Science·29 Mar 201817. How many times does the letter A print in the following code? for (int i = -1; i < 3; i++) { System.out.println("A") (A) 4 (B) 2 (C) 1 (D) 3 (E) 0
OC userin Computer Science·29 Mar 20184. In Java, each object gets its own copy of the static class variables. (A) FALSE (B) TRUE
OC userin Computer Science·25 Mar 20182. Recall that an XOR gate is a digital logic gate that gives a true (1) output when the two inputs are different, and false (0) otherwise. An equivalent XOR function with inputs A and B can be implemented in Excel 2010 using the formula: a) = AND(OR(A,B), NOTAND(A,B))) b) =A<>B c) = NOT(NOT(A<>B)) d) EAND(NOT(AND(A,B)), OR(A, B)) e) All of the above x
OC userin Computer Science·25 Mar 201838. Imagine we have the following configuration in an instance of graph: If the node 0 is at position 0 in the graph, and we print its content, what would be printed into the console, e.g. System.out.println (graph[0]);?. N.B. The ordering of Nodes written after connected to: is unimportant. (A) 3 is connected to: (B) 1 is connected to: (C) O is connected to: (D) O is connected to: (E) 0 is connected to: 0, 1, 2, 3, 4, 0, 3 1, 3, , 1, 3
OC userin Computer Science·24 Mar 20188. Write a class called WordSet representing a set of String objects which can contain an arbitrary number of strings, limited only by the memory available to the Java Virtual Machine. A set is a collection of elements, however, unlike a list, a set cannot contain duplicate elements. Therefore, as its name implies, a WordSet object cannot contain duplicate Strings that is, if one attempts to da String to a Wordset, and the wordset already contains an element which is equal to this string, the attempt will fail and the state of the Wordset will not change. All String comparisons performed in the methods defined in the Wordset class are done in a Case SENSITIVE manner. Note that in the method descriptions below, the phrase "this Wordset" means "the Wordset on which the method in question is called." Your Wordset class MUST provide the following INSTANCE methods • A constructor, which takes no parameters and initializes the new Wordset ohject so that it contains no elements • A method called add(), which takes as its only parameter a string and returns a value of type boolean. If this Wordset already contains a string which is equal to the parameter string, or the parameter String is null, then the state of this Wordset does not change and the method return false; otherwise, the parameter String is added to this Wordset. and the method returns true. • A method called remove().which takes as its only parameter a string and returns a value of type boolean. If this wordSet contains a string which is equal to the parameter String this string is removed from the WordSet and the method returns true. On the other hand, if the string parameter is null or this Wordset does not contain a string which is equal to the parameter string, then the state of this wordset does not change, and the method return false. • A method called get.size(), which takes no parameters and returns the number of strings currently stored in this Wordset. This method MUST NOT change the state of this Wordset. • A method called isMember(). which takes as its only parameter a string and retumsa value of type boolean which is true if this wordset contains the parameter String false otherwise. If the parameter String is null, this method also return false. This method MUST NOT change the state of this wordset. • A method called computebirrerence().which takes as its only parameter a Wordset and returns a new Wordset representing the difference between this wordset and the parameter Wordset: in other words, the WordSet returned by this method contains all the strings that are in this wordset, but not in the parameter Wordset. If the parameter Wordset contains all the elements of this WordSet or this WordSet contains no elements, then this method returns a new Wordset containing no elements. Finally, if the parameter Wordset is null or contains ne strings, then this method returns a new wordset which contains all the elements of this wordset. This method MUST NOT change the state of this wordset or the parameter Wordset. • A method called tostring , which takes the parameters and turns a string which is the textual representation of this wordset. This textual representation consists of the concatena tion of the following clements - The String - The text representation of each clement in the WordSet; cach pair of adjacent clements is separated by the String", but this String MUST NOT appear before the first clement or after the last element - The String") The order in which the elements of this Wordset appear in the textual representation generated by the tostring() method does not matter. If the WordSet contains to Brings, then the textual representation returned by this method is ". Note that you MUST respect proper encapsulation practices that is, the attributes and methods of your class MUST be declared using the proper visibility modifier NINT Um an array list (of string) to keep track of the string stored in a wordt ob joot Is there a method defined in the Array loist class which determines whether in clementis already wored in an array ist, and which will do a case-sensitive comparison when liked on an Arraylint of strings? See the pages 24-26 of this examination for information about potentially useful methods defined by the ArrayList class WRITE YOUR Wordset CLASS IN THE SPACE BELOW:
OC userin Computer Science·21 Mar 2018I DOLCI 9. Consider a method with the header: public static void method (String x) Is method ( (String) 10) a valid way to call it? Write YES or NO