0% 0 votes, 0 avg 28 1234567891011121314151617181920 This quiz randomly generates 20 questions as asked in AP Computer Science A (AP CSA) - Programming in Java. Congratulations! AP Computer Science A (AP CSA) - Programming in Java This quiz randomly generates 20 questions (in 30 mins) as asked in AP Computer Science A (AP CSA) - Programming in Java. 1 / 20 What is the output? The largest of 'a', 'b', and 'c'. Value of 'c' Error No output The code generates random numbers for 'a', 'b', and 'c' and prints the largest of the three values. If two values are equal and the largest, it prints the first one. 2 / 20 What is the output? Nothing is printed An Exception is thrown Compile Error May 15, 2004 3 / 20 Which of the following code segments will correctly find the index of the first string in ArrayList words that starts with the letter "B"? If no such string exists, it should return -1. for (String s : words) { if (s.substring(0, 1).equals("B")) return words.indexOf(s); } return -1; for (int i = 0; i < words.size(); i++) { if (words.get(i).substring(0, 1).equals("B")) return i; } return -1; Both A and B are correct. Neither A nor B is correct. 4 / 20 What is the output? 10 : 30 : 4 10 : 30 : 5 10 : 30 : 6 Compilation Error 5 / 20 Question c ‹ a is false. c ‹ a is true. a ‹ b is false. c == a * b is true. c == a * b is true, and c ‹ a is true. 6 / 20 8 bits is enough to represent 256 different numbers. How many total bits do you need to represent 512 (twice as many) numbers? 9 bits 10 bits 16 bits 17 bits 7 / 20 What is the output ? Compilation fails 3 5 0 0 9 25 Class constructor will initialize values of x and y. No problem and easy. 8 / 20 What is the output ? (double) 3/4 0 0.0 0.75 Compilation Error 9 / 20 What is the result of the following expression in Java? 5 6 8 11 10 / 20 Which of the following expressions is equivalent to !(x < 5 && y >= 10)? x >= 5 || y < 10 x >= 5 && y < 10 x > 5 || y <= 10 x > 5 && y < 10 A: This is De Morgan’s Law. You negate x < 5 (which becomes x >= 5), negate y >= 10 (which becomes y < 10), and change the && to ||. 11 / 20 What is the output? C B A C A B C Compilation fails at line n1 and line n2 12 / 20 A programmer is designing a program to catalog all books in a library. He plans to have a Book class that stores features of each book: author, title, isOnShelf and so on, with operations like getAuthor, getTitle, getShelfInfo, and setShelfInfo. Another class, LibraryList, will store an array of Book objects. The LibraryList class will include operations such as listAllBooks, addBook, removeBook, and searchForBook. The programmer plans to implement and test the Book class first, before implementing the LibraryList class. The programmer's plan to write the Book class first is an example of top-down development. bottom-up development. procedural abstraction. information hiding. a driver program. The programmer is using an object-oriented approach to writing the program and plans to test the simplest classes first. This is bottom-up development. In top down development (choice A), high-level classes are broken down into subsidiary classes. Procedural abstraction (choice C) is the use of helper methods in a class. Information hiding (choice D) is restriction of access to private data and methods in a class. Choice E is wrong because a driver program is one whose sole purpose is to test a given method or class. Implementing the simplest classes hrst may involve driver programs that test the various methods, but the overall plan is not an example of a driver program. 13 / 20 What is the output? An exception is thrown at runtime. 07-31-2014 2014-07-31 2014-09-30 14 / 20 What output will be produced by invoking secondTestMethod for a Tester object, assuming that testArray contains 3, 4, 5? 3 4 5 4 5 6 5 6 7 0 0 0 No output will be produced. An ArrayIndexOutDfBoundsException will be thrown. The array will not be changed by the increment method. Nor will the local variable element! What will be changed by increment is the copy of the parameter during each pass through the loop. 15 / 20 Which of the following is true about arithmetic operations? I. An arithmetic operation that uses two integer values will evaluate to an integer value. II. It is impossible to add 1 to a variable without ever using the number 1 in a statement. III. An arithmetic operation that uses a double value will evaluate to a double value. I only II only I and II I and III I, II, and III Statement I is true because in most programming languages (like Java), an arithmetic expression consisting only of integer values will always evaluate to an integer value; the fractional part (if any) is truncated, not rounded. For example, 7 / 2 results in 3, not 3.5. Statement III is true because if any value in an arithmetic operation is a double (floating-point) value, the entire expression generally evaluates to a double value to maintain precision. Type conversion occurs so that the operation is performed with floating-point arithmetic. 16 / 20 Refer to the code: Consider the implementation of a writeDeck method that is added to the Deck class. I only II only Ill only I and Ill only II and III only 17 / 20 Question myHrs = 0; myMins = 0; my Secs = 0; myHrs = h; myMins = m; mySecs = s; resetTime(myHrs, myMins, mySecs); h = myHrs;m = myMins; s = mySecs; Time = new Time(h, m, s) ; 18 / 20 What is the best explanation for why digital data is represented in computers in binary? The binary number system is the only system flexible enough to allow for representing data other than numbers. It's easier, cheaper, and more reliable to build machines and devices that only have to distinguish between binary states. It typically takes fewer digits to represent a number in binary when compared to other number systems (for example, the decimal number system) It's impossible to build a computing machine that uses anything but binary to represent numbers 19 / 20 Question r = a.plus(r); a = r. plus (new Rational (n)); r = r.plus(r); a = n. plus(r); r = r. plus (new Rational(n)); 20 / 20 What is the output? Other number Remainder 1 Multiple of 11 Error int specialNum = (int)(100 * Math.random()); Math.random() generates a random double value that is greater than or equal to 0.0 and less than 1.0. Multiplying this by 100 yields a number in the range [0.0, 100.0). Casting to (int) truncates the decimal part, resulting in a random integer between 0 and 99, inclusive. This value is stored in the specialNum variable. if ((specialNum % 11) == 0) This condition uses the modulo operator (%) to find the remainder when specialNum is divided by 11. If the remainder is 0, the program executes the next line and prints "Multiple of 11". else if ((specialNum % 11) == 1) This condition is checked only if the first if condition is false. If the remainder when divided by 11 is 1, the program executes the next line and prints "Remainder 1". else This block is executed if neither of the preceding conditions is true (i.e., the remainder is not 0 and not 1). It prints "Other number". Your score is 0% Restart quiz