Computer Programming Trimester B Final Course: 110201B-2 Final----Room #: 147 2010 Teacher: Jason Neagle Computer Programming Trimester B Final 2010 Directions: 1-4 Choose what is printed with the code. 1) System.out.println(3/4+5*2/33-3+8*3); a) 21 b) -33 c) 22 d) 24 2) int i=10, j=3; boolean true_false; true_false=(j!=i); System.out.println(true_false); a) True b) False c) Won’t compile d) Error 3) System.out.println(!(3<5)); a) True b) False c) Error d) 5 4) double d=29.78; int i=d; a) 29 b) 78 c) Error d) Nothing; Won’t compile Directions: 5-20 Answer the question the best to your knowledge. 5) Which is NOT a Legal string name? a) Agrp b) Hopper_gee c) D28 d) 3aster 6) What is a char? a) A command b) A character c) A statement d) Not anything 7) How do you tell the program to print a line of text? a) System.out.println(“enter your text here”); b) Int = your text; c) You can’t print text 1 © Bobby McAtee All Rights Reserved. Computer Programming Trimester B Final d) You don’t know 8) How do you allow the u6uyser to give input? a) You hope it works b) You yell at the computer c) Use the buffered reader class or the kbreader class d) You shut off the computer 9) How do you declare a number? a) With an int variable b) Type random commands c) System.out.println d) Kbreader class 10) What is an “i” statement? a) Gives the user different results pending on the input b) A question about programming c) A stupid question d) A way to confuse yourself in programming 11) What type of variable would you use to store your name? a) String b) Int. c) Double d) None of the above 12) What was the title of Lesson 1? a) Goodbye Earth b) Beginning c) Hello World d) None of the above 13) What type of variable is used to store integers? a) String b) Int. c) Double d) All of the above 14) E=_______? a) AD3 b) MC2 c) 00 d) 100/48 15) What is the first step in PEMDAS? a) Subtract b) Divide c) Multiply d) Parenthesis 16) What sign do you use for concatenation? a) / b) \ c) + d) * 2 © Bobby McAtee All Rights Reserved. 2010 Computer Programming Trimester B Final 2010 17) How many possible values does the Boolean variable type have? a) 4 b) 6 c) 3 d) 2 18) What are the three variable types? a) Double, declared, int. b) String, int., double c) Int., declared, initialized d) Declared, string, int. 19) What does concatenation do? a) Combine two strings b) Find the number of characters in a string c) Pick out a piece of a string d) Find the number of characters in a substring 20) Which of the following are legal variable names? a) D b) hopper_gee c) hopper-gee d) a and b e) a and c f) b and c g) a, b, and c Directions: 21-24 Answer the question using the provided code. 21) Which of the following is a possible output for the following code? Random rd = new Random( ); System.out.println( rd.nextlnt(36) ); a) 0 b) 36 c) 37 d) Throws an exception e) None of the above 22) Which of the following is a possible output of the following code? Java.util.Random rd = new java.util.Random( ); System.out.println( 1 + 5 * rd.nextDouble( ) ); a) 0 b) .9999 c) 5.0 3 © Bobby McAtee All Rights Reserved. Computer Programming Trimester B Final 2010 d) 6.0 e) None of these 23) To simulate the result of the rolling a normal 6-sided die, what should replace <*l>? Public static int dieOutcome( ) { Random rdm = new Random( ); Int die = <*l> Return die; } a) Rdm.nextDouble(6); b) Rdm.nextlnt(7); c) 1+rdm.nextInt(6); d) 1+rdm.Double(7); e) 1+rdm.nextDouble(6) 24) What would be the replacement code for <*1> to generate random numbers from the following set? {20, 35, 50, 65} Random ri = new Random( ); Int ri = <*l> a) b) c) d) e) 20*15+ri.nextInt(4); 20+15*ri.nextInt(5); 15*20+ri.nextInt(4); 15+20*ri.nextInt(5); None of these Directions: 25-27 Answer the question the best to your knowledge. 25) When a class has more than one method of the same name, this is called which of the following? a) Overloading b) Inheritance c) Overriding d) Polymorphism e) None of these 26) Who is the author of the Blue Pelican Java book? a) Charles E. Cook b) Charles E. Dickens c) Jason Neagle d) Steve E. Cook 27) What is used to store “floating point” numbers (decimal fractions)? a) String b) Int c) Double © Bobby McAtee All Rights Reserved. 4 Computer Programming Trimester B Final 2010 d) Ping Directions: 28-29 Is the code legal? 28) int arws = 47.4; a) Yes it will compile b) No it won’t compile c) I don’t know d) Who cares 29) Double d = 103; a) Yes it will compile b) No it won’t compile c) I don’t know d) Who cares Directions: 30-37 Answer the question the best to your knowledge. 30) X++ increments x ________ it is used in the statement. a) Before b) After c) During 31) ++X increments x ________ it is used in the statement. a) Before b) After c) During 32) X-- decrements x _________ it is used in the statement. a) Before b) After c) During 33) --X decrements x __________ it is used in the statement. a) Before b) After c) During 34) What code returns the absolute value of x? a) Int abs(int x) b) Double PI c) Double random( ) d) Double sqrt(double x) 35) What code returns the square root of x? a) Int abs(int x) b) Double PI c) Double random( ) d) Double sqrt(double x) 5 © Bobby McAtee All Rights Reserved. Computer Programming Trimester B Final 2010 36) What code returns 3.14159625…….? a) V= Int abs(int x) b) Double PI c) Double random( ) d) Double sqrt(double x) 37) What code a random double (range 0<r,1) a) Int abs(int x) b) Double PI c) Double random( ) d) Double sqrt(double x) Directions: 38-40 Choose what is printed with the code given. 38) Double d = -379.22; System.out.println( Math.abs(d) ); a) 379.22 b) 379 c) 380 d) None of the above 39) Double b = 42.01; Double e = 3.728; System.out.println ( Math.pow(b, e) ); a) 1126831.03 b) 1126831 c) 1126831.027 d) 11.26831.027 40) Double d = 1.4; System.out.println( Math.ceil(d) ); a) b) c) d) 1.0 3.0 2.0 -2.0 6 © Bobby McAtee All Rights Reserved.