Upload
donhu
View
239
Download
2
Embed Size (px)
Citation preview
Exposure Java Multiple Choice TestChapter 5 Keyboard Input & Control Structures
DO NOT WRITE ON THIS TESTThis test includes program segments, which are not complete programs. Answer such questions with the assumption that the program segment is part of a correct program.
There is a Reference Guide for the Expo class and a Graphics Sheet at the end of this test.
01. Which of the following should be used to enter a word ?
(A) Expo.enterBoolean();(B) Expo.enterChar();(C) Expo.enterDouble();(D) Expo.enterInt();
(E) Expo.enterString();
02. Which of the following should be used to enter a sentence?
(A) Expo.enterBoolean();(B) Expo.enterChar();(C) Expo.enterDouble();(D) Expo.enterInt();
(E) Expo.enterString();
03. Which of the following should be used to enter somebody's name?
(A) Expo.enterBoolean();(B) Expo.enterChar();(C) Expo.enterDouble();(D) Expo.enterInt();
(E) Expo.enterString();
04. Which of the following should be used to enter your age?
(A) Expo.enterBoolean();(B) Expo.enterChar();(C) Expo.enterDouble();
(D) Expo.enterInt();(E) Expo.enterString();
05. Which of the following should be used to enter your gpa?
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 1 Updated: 05-22-13
(A) Expo.enterBoolean();(B) Expo.enterChar();
(C) Expo.enterDouble();(D) Expo.enterInt();(E) Expo.enterString();
06. Which of the following should be used to enter an integer?
(A) Expo.enterBoolean();(B) Expo.enterChar();(C) Expo.enterDouble();
(D) Expo.enterInt();(E) Expo.enterString();
07. Which of the following should be used to enter a real number?
(A) Expo.enterBoolean();(B) Expo.enterChar();
(C) Expo.enterDouble();(D) Expo.enterInt();(E) Expo.enterString();
08. Which of the following should be used to enter your middle initial?
(A) Expo.enterBoolean(); (B) Expo.enterChar();
(C) Expo.enterDouble();(D) Expo.enterInt();(E) Expo.enterString();
09. Program Flow follows the exact sequence of program statements, unless directed otherwise by a Java _______ _______.
(A) traffic controller(B) redirect command
(C) control structure(D) structural integrity
Use the table below to answer questions 10 through 14.
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 2 Updated: 05-22-13
10. Which cell demonstrates Simple Sequence?
(A) Cell I(B) Cell II(C) Cell III(D) Cell IV(E) Cell V
11. Which cell demonstrates One-Way Selection?
(A) Cell I(B) Cell II(C) Cell III
(D) Cell IV(E) Cell V
12. Which cell demonstrates Two-Way Selection?
(A) Cell I(B) Cell II(C) Cell III(D) Cell IV
(E) Cell V
Use the table below to answer questions 10 through 14.
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 3 Updated: 05-22-13
13. Which cell demonstrates Multi-Way Selection?
(A) Cell I (B) Cell II
(C) Cell III(D) Cell IV(E) Cell V
14. Which cell demonstrates Repetition?
(A) Cell I(B) Cell II
(C) Cell III(D) Cell IV(E) Cell V
15. Which of the following are synonyms for Selection?
(A) Decision Making and Looping (B) Decision Making and Conditional Branching
(C) Looping and Conditional Branching(D) Looping and Iteration(E) Iteration and Decision Making
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 4 Updated: 05-22-13
16. Which of the following are synonyms for Repetition?
(A) Decision Making and Looping(B) Decision Making and Conditional Branching(C) Looping and Conditional Branching
(D) Looping and Iteration(E) Iteration and Decision Making
17. In Java, if..else is an example of
(A) 1-Way Selection. (B) 2-Way Selection.
(C) Multi-Way Selection(D) Fixed Repetition.(E) Conditional Repetition.
18. In Java, if (without else) is an example of
(A) 1-Way Selection.(B) 2-Way Selection.(C) Multi-Way Selection(D) Fixed Repetition.(E) Conditional Repetition.
19. In Java, switch is an example of
(A) 1-Way Selection.(B) 2-Way Selection.
(C) Multi-Way Selection(D) Fixed Repetition.(E) Conditional Repetition.
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 5 Updated: 05-22-13
20. Which of the following Java commands are used with switch?
(A) case(B) break(C) default
(D) All of the above
21. for is an example of
(A) 1-Way Selection.(B) 2-Way Selection.(C) Multi-Way Selection
(D) Fixed Repetition.(E) Conditional Repetition.
22. while is an example of
(A) 1-Way Selection.(B) 2-Way Selection.(C) Multi-Way Selection(D) Fixed Repetition.
(E) Conditional Repetition.
23. Which of the following are Java relational operators?
(A) ==, <, >, <=, >=, !=(B) &&, ||, !(C) +, -, *, /, %(D) +=, -=, *=, /=, %=
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 6 Updated: 05-22-13
Use this program below to answer questions 24 through 26.
24. What is the output of this program after the user enters 600000 ?
(A) 0(B) 2500
(C) Christmas bonus: 0(D) Christmas bonus: 2500
25. What is the output of this program after the user enters 800000 ?
(A) 0(B) 2500(C) Christmas bonus: 0
(D) Christmas bonus: 2500
26. What is the output of this program after the user enters 750000 ?
(A) 0(B) 2500(C) Christmas bonus: 0
(D) Christmas bonus: 2500
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 7 Updated: 05-22-13
Use this program below to answer questions 27 and 28.
27. What is the output of this program after the user enters 999999 ?
(A) 0(B) 3000
(C) Christmas bonus: 0(D) Christmas bonus: 3000(E) CONGRATULATIONS!
You sold a million dollars in merchandise! You will receive a $3000 Christmas Bonus! Keep up the good work! Christmas bonus: 3000
28. What is the output of this program after the user enters 1500000 ?
(A) 0(B) 3000(C) Christmas bonus: 0(D) Christmas bonus: 3000
(E) CONGRATULATIONS! You sold a million dollars in merchandise! You will receive a $3000 Christmas Bonus! Keep up the good work! Christmas bonus: 3000
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 8 Updated: 05-22-13
Use this program below to answer questions 29 and 30.
29. What is the output of this program after the user enters 400 ?
(A) 400(B) You are admitted(C) You are rejected
(D) You are not admitted
30. What is the output of this program after the user enters 1600 ?
(A) 400 (B) You are admitted
(C) You are rejected(D) You are not admitted
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 9 Updated: 05-22-13
Use this program below to answer questions 31 and 32.
31. What is the output of this program segment after the user enters 1600 ?
(A) You are admitted.
(B) You are not admitted.
(C) You are admitted. Perfect! You are a genius!
(D) You are not admitted. Perfect! You are a genius!
32. Assume the user enters a valid integer in the range of 400..1600 Which is the following is NOT a possible output of the program above?
(A) You are admitted.
(B) You are not admitted.
(C) You are admitted. Perfect! You are a genius!
(D) You are not admitted. Perfect! You are a genius!
(E) This question cannot be answered without knowing what the user entered.
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 10 Updated: 05-22-13
33. What is the output of this program after the user enters C ?
(A) 70..79 Average
(B) 60..69 Average
(C) Below 60 Average
(D) 70..79 Average60..69 AverageBelow 60 Average
(E) 90..100 Average80..89 Average70..79 Average60..69 AverageBelow 60 Average
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 11 Updated: 05-22-13
Use this program below to answer questions 34 and 35.
34. What is the output of this program after the user enters C ?
(A) 70..79 Average(B) 60..69 Average(C) Below 60 Average(D) All of the above will be displayed.(E) Invalid Input.
35. What is the output of this program after the user enters G ?
(A) 70..79 Average(B) 60..69 Average(C) Below 60 Average(D) All of the above will be displayed.
(E) Invalid Input.
36. What is the output of this program after the user enters a ?
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 12 Updated: 05-22-13
(A) 90 .. 100 Average Excellent!
(B) 80 .. 89 Average Good
(C) 70 .. 79 Average Fair
(D) Below 60 Average Bad
(E) No Match Found
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 13 Updated: 05-22-13
37. What is the output of this program after the user enters a ?
(A) 90 .. 100 Average Excellent!
(B) 80 .. 89 Average Good
(C) 70 .. 79 Average Fair
(D) Below 60 Average Bad
(E) No Match Found
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 14 Updated: 05-22-13
38. What is the output of this program segment?
for (int p = 10; p <= 20; p++) System.out.print(p + " ");
(A) 10 11 12 13 14 15 16 17 18 19 20
(B) 10 11 12 13 14 15 16 17 18 19
(C) 20 19 18 17 16 15 14 13 12 11 10
(D) 20 19 18 17 16 15 14 13 12 11
39. What is the output of this program segment?
for (int p = 10; p < 20; p++) System.out.print(p + " ");
(A) 10 11 12 13 14 15 16 17 18 19 20
(B) 10 11 12 13 14 15 16 17 18 19
(C) 20 19 18 17 16 15 14 13 12 11 10
(D) 20 19 18 17 16 15 14 13 12 11
40. What is the output of this program segment?
for (int p = 20; p > 10; p--) System.out.print(p + " ");
(A) 10 11 12 13 14 15 16 17 18 19 20
(B) 10 11 12 13 14 15 16 17 18 19
(C) 20 19 18 17 16 15 14 13 12 11 10
(D) 20 19 18 17 16 15 14 13 12 11
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 15 Updated: 05-22-13
41. What is the output of this program segment?
for (int p = 20; p >= 10; p--) System.out.print(p + " ");
(A) 10 11 12 13 14 15 16 17 18 19 20
(B) 10 11 12 13 14 15 16 17 18 19
(C) 20 19 18 17 16 15 14 13 12 11 10
(D) 20 19 18 17 16 15 14 13 12 11
42. What is the output of this program segment?
for (int p = 3; p <= 30; p+=5) System.out.print(p + " ");
(A) 5 10 15 20 25 30
(B) 3 6 9 12 15 18 21 24 27 30
(C) 3 8 13 18 23 28
(D) 3 8 13 18 23 28 33
43. What is the output of this program segment?
for (double p = 2.50; p <= 4.00; p+=0.25) System.out.print(p + " ");
(A) 2.5 3.5
(B) 2.5 3.5 4.5
(C) 2.5 2.75 3.0 3.25 3.5 3.75
(D) 2.5 2.75 3.0 3.25 3.5 3.75 4.0
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 16 Updated: 05-22-13
44. What is the output of this program segment?
for (double p = 2.50; p < 4.00; p+=0.25) System.out.print(p + " ");
(A) 2.5 3.5
(B) 2.5 3.5 4.5
(C) 2.5 2.75 3.0 3.25 3.5 3.75
(D) 2.5 2.75 3.0 3.25 3.5 3.75 4.0
45. What is the output of this program segment?
for (int p = 3; p < 50; p*=2) System.out.print(p + " ");
(A) 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49
(B) 3 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50
(C) 3 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48
(D) 3 6 12 24 48
(E) 3 6 12 24
46. What is the output of this program segment?
for (int p = 1024; p > 1; p/=2) System.out.print(p + " ");
(A) 1024 512 256 128 64 32 16 8 4 2 1
(B) 1024 512 256 128 64 32 16 8 4 2
(C) 512 256 128 64 32 16 8 4 2 1
(D) 512 256 128 64 32 16 8 4 2
47. What is the output of this program segment?
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 17 Updated: 05-22-13
for (int p = 512; p >= 1; p/=2) System.out.print(p + " ");
(A) 1024 512 256 128 64 32 16 8 4 2 1
(B) 1024 512 256 128 64 32 16 8 4 2
(C) 512 256 128 64 32 16 8 4 2 1
(D) 512 256 128 64 32 16 8 4 2
48. What is the output of this program segment?
for (char p = 'A'; p < 'Z'; p++) System.out.print("Hello");
(A) 26 Hellos in one column going down the screen(B) 25 Hellos in one column going down the screen(C) 26 Hellos going across the screen word-wrapping around to a second line
(D) 25 Hellos going across the screen word-wrapping around to a second line
49. What is the output of this program segment?
for (char p = 'Z'; p >= 'A'; p--) System.out.println("Hello");
(A) 26 Hellos in one column going down the screen(B) 25 Hellos in one column going down the screen(C) 26 Hellos going across the screen word-wrapping around to a second line(D) 25 Hellos going across the screen word-wrapping around to a second line
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 18 Updated: 05-22-13
50. How many Hellos will this loop display?
for (int p = 1; p <= 10; p++) System.out.print("Hello");
(A) 10 (B) 9 (C) 5 (D) 2 (E) 1
51. How many Hellos will this loop display?
for (int p = 1; p < 10; p++) System.out.print("Hello");
(A) 10 (B) 9 (C) 5 (D) 2 (E) 1
52. How many Hellos will this loop display?
for (int p = 1; p <= 10; p+=2) System.out.print("Hello");
(A) 10 (B) 9 (C) 5 (D) 2 (E) 1
53. How many Hellos will this loop display?
for (int p = 5; p <= 10; p*=2) System.out.print("Hello");
(A) 10 (B) 9 (C) 5 (D) 2 (E) 1
54. You want your program to be protected with a password. Which control structure(s) would you need at the beginning of your program?
I. ifII. forIII. while
(A) I only(B) II only(C) III only(D) I and II
(E) I and III
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 19 Updated: 05-22-13
55. What is the output of this program after the user enters 7, followed by a 2 ?
(A) 7(B) 2(C) 9
(D) 72(E) 27
56. What is the flag in this program segment?
int grade = 0; while(grade >= 0) {
System.out.print("Enter a grade: "); grade = Expo.enterInt();
}
(A) grade(B) 0(C) any positive number
(D) any negative number
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 20 Updated: 05-22-13
57. What is the output of this program?
(A) (B)
(C) (D)
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 21 Updated: 05-22-13
58. What is the output of this program?
(A) (B)
(C) (D)
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 22 Updated: 05-22-13
59. What is the output of this program?
(A) (B)
(C) (D)
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 23 Updated: 05-22-13
60. What is the output of this program?
(A) (B)
(C) (D)
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 24 Updated: 05-22-13
Abridged Reference Sheet for the Expo Class to help with the Chapter 5 Test
Expo.drawPixel(g,100,200);
Draws a very small single dot (pixel) on the computer screen 100 pixels over and 200 pixels down.
Expo.drawPoint(g,100,200);Draws a larger (3 pixel by 3 pixel) dot on the computer screen 100 pixels over and 200 pixels down.
Expo.drawLine(g,100,200,300,400);Draws a line segment connecting the starting coordinate point (100,200) with the ending point (300,400).
Expo.drawCircle(g,300,200,100);Draws an open circle with a radius of 100 pixels whose center is located at the coordinate (300,200).
Expo.drawOval(g,300,200,100,50);Draws an open oval with a horizontal radius of 100 pixels and a vertical radius of 50 pixels.The center of this oval is located at the coordinate (300,200).
Expo.drawRectangle(g,100,200,300,400);Draws an open rectangle whose upper-left-hand coordinate is (100,200) and whose lower-right-hand coordinate is (300,400).
Expo.setColor(g,Expo.red);
Changes the current drawing color to red. 36 color constants are built into the Expo class.
Expo.fillRectangle(g,100,200,300,400);Draws a solid “filled-in” rectangle.
Expo.fillCircle(g,300,200,100);Draws a solid “filled-in” circle.
Expo.fillOval(g,300,200,100,50);Draws a solid “filled-in” oval.
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 25 Updated: 05-22-13
Graphics Sheet - 1000 x 6500,0 25 50 75 100 125 150 175 200 225 250 275 300 325 350 375 400 425 450 475 500 525 550 575 600 625 650 675 700 725 750 775 800 825 850 875 900 925 950 975 999
25
50
75
100
125
150
175
200
225
250
275
300
325
350
375
400
425
450
475
500
525
550
575
600
625
649
Exposure Java 2013, PreAPCS Edition Chapter 5 Test Page 26 Updated: 05-22-13