Docsity

Midterm Exam 1 for Introduction to Java Programming | CS 1054, Exams of Java Programming

Toggle sidebar
bg1
CS 1054 Intro to Java Programming Midterm
Summer I 2006 Page 1 of 9
READ THIS NOW!
Failure to read and follow the instructions below may result in severe penalties.
Failure to adhere to these directions will not constitute an excuse or defense.
• Print your name and VT email in the space provided below on the test.
• Print your name and VT ID number (NOT your SSN) on the Opscan.
• Choose the single best answer for each question — some answers may be partially correct. If you mark more
than one answer, it will be counted wrong.
• Unless a question involves determining whether given Java code is syntactically correct, assume that it is. The
code has been compiled and tested, except where there are deliberate errors. Unless a question specifically deals
with Java import directives, you should assume the necessary library files have been imported.
• When you have completed the test, sign the pledge at the bottom of this page and turn in the test & Opscan.
• Note that questions about output printed values disregard formatting completely.
• In questions/answers which require a distinction between integer and real values, integers will be represented
without a decimal point, whereas real values will have a decimal point, [ 1054 (integer), 1054.0 (real)].
• When you have completed the test, sign the pledge at the bottom of this page and turn in the test & Opscan.
• This is a closed-book, closed-notes examination. No calculators or other electronic devices may be used
during this examination. You may NOT discuss (in any form: written, verbal or electronic) the content of
this examination with any student who has not taken it. You must return this test form when you complete
the examination. Failure to adhere to any of these restrictions is an Honor Code violation.
• Mark your answers on the test form, for future reference, and on the Opcan. The answers you mark on the
Opscan form will be considered your official answers. There are 30 multiple-choice questions.
Do not start the test until instructed to do so!
Name (print: Last name, First)
VT Email: (print: campus email address)
Pledge: On my honor, I have neither given nor received unauthorized aid on this examination.
signature
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Midterm Exam 1 for Introduction to Java Programming | CS 1054 and more Exams Java Programming in PDF only on Docsity!

Summer I 2006 Page 1 of 9

READ THIS NOW!

Failure to read and follow the instructions below may result in severe penalties. Failure to adhere to these directions will not constitute an excuse or defense.

  • Print your name and VT email in the space provided below on the test.
  • Print your name and VT ID number (NOT your SSN) on the Opscan.
  • Choose the single best answer for each question — some answers may be partially correct. If you mark more than one answer, it will be counted wrong.
  • Unless a question involves determining whether given Java code is syntactically correct, assume that it is. The code has been compiled and tested, except where there are deliberate errors. Unless a question specifically deals with Java import directives, you should assume the necessary library files have been imported.
  • When you have completed the test, sign the pledge at the bottom of this page and turn in the test & Opscan.
  • Note that questions about output printed values disregard formatting completely.
  • In questions/answers which require a distinction between integer and real values, integers will be represented without a decimal point, whereas real values will have a decimal point, [ 1054 (integer), 1054.0 (real)].
  • When you have completed the test, sign the pledge at the bottom of this page and turn in the test & Opscan.
  • This is a closed-book, closed-notes examination. No calculators or other electronic devices may be used during this examination. You may NOT discuss (in any form: written, verbal or electronic) the content of this examination with any student who has not taken it. You must return this test form when you complete the examination. Failure to adhere to any of these restrictions is an Honor Code violation.
  • Mark your answers on the test form, for future reference, and on the Opcan. The answers you mark on the Opscan form will be considered your official answers. There are 30 multiple-choice questions.

Do not start the test until instructed to do so!

Name (print: Last name, First)

VT Email: (print: campus email address)

Pledge: On my honor, I have neither given nor received unauthorized aid on this examination.

signature

Summer I 2006 Page 2 of 9

1) Consider the following Java declaration statement:

Text msg = new Text( new String(“Help me!”), 60, 90, canvas );

How many objects are instantiated by the statement above?

  1. 1 2) 2 3) 0 4) none of these

2) Consider the partial Java class code below:

public class Midterm2Q2 extends FrameWindowController { private FramedOval circle;

public void begin() { circle = new FramedOval(25, 25, 40, 50, canvas ); }

public void ______________(Location point) // circle jumps to the mouse { circle.moveTo(point); } }

Which of the following mouse events below should replace the underscored line above to cause the circle object to always follow the mouse in the window?

  1. onMouseClick 2) onMouseDrag

  2. onMouseEnter 4) onMouseRelease

  3. onMouseExit 6) onMouseMove

  4. onMousePress 8) None of the above

Summer I 2006 Page 4 of 9

For the next two questions (6–7), consider the partial Java class code below:

public class Midterm5Q5678 extends FrameWindowController { private FilledRect background;

//completely cover the canvas background with blue public void begin() { background = new FilledRect( __________ , //X-coordinate of upperleft

__________ , //Y-coordinate of upperleft

__________ , //width of box

__________ , //height of box

canvas ); background.setColor( Color.BLUE ); }

}

6) Which of the following statements should replace the first underscored line above to position the upperleft X- coordinate of the background box correctly?

  1. 1 2) 0

  2. canvas.getHeight() 4) canvas.getWidth()

  3. canvas.getSize() 6) canvas.getX()

  4. 400 8) None of the above

7) Which of the following statements should replace the fourth underscored line above to give the correct height of the background box?

  1. canvas.getY() 2) canvas.getX() + canvas.getY()

  2. canvas.getHeight() 4) canvas.getWidth()

  3. canvas.getSize() 6) canvas.getX()

  4. 400 8) None of the above

Summer I 2006 Page 5 of 9

For the next two questions (8-9), consider the Java class code below:

public class Midterm89 {

public void question8() { String str8a = “I love summer”; String str8b = new String(“I love summer”); if ( str8a == str8b ) System.out.println(“true”); else System.out.println(“false”); }

public void question9() { String str9a = “I love summer”; String str9b = new String(“I love summer”); if ( str9a.equals(str9b) ) System.out.println(“true”); else System.out.println(“false”); }

}

Given the following segment in Midterm89 client code:

Midterm89 q8 = new Midterm89(); q8.question8();

8) What is the output produced by the above code?

  1. true 2) false 3) none of these

Assuming the Midterm89 class from the previous questions, given the following segment of Midterm89 client code:

Midterm89 q9 = new Midterm89(); q9.question9();

9) What is the output produced by the above code?

  1. true 2) false 3) none of these

For the following 3 questions, select the value of the given Java arithmetic expression. Note that the presence of a decimal indicates a double value, rather than an int.

10) 2.0 + 5.0 / 2.0 4.5 4.0 3.5 3.0 none of these

11) 5 – 5 / 2 0 2.5 3 -2.5 none of these

12) 11 % 4 + 3 10 6.75 5 4 none of these

Summer I 2006 Page 7 of 9

19) What is the value printed for the variable Beta if the following code is executed?

int Beta = 2, X = 3;

if ( X % 2 == 1 ) Beta = Beta + X; X++;

if ( X / 5 == 0 ) Beta = Beta + X; X++;

if ( X / 5 == 0 ) Beta = Beta + X;

System.out.println( " Beta = " + Beta);

  1. none of these

For the following 2 questions, consider the execution of the following code fragment:

int x = 3, y = 8; while (x > 0) { x--; y = y - x; System.out.println( "y = " + y ); } System.out.println( "x = " + x );

20) What value is printed for the variable y on the next to last line of output?

  1. 6 7) 0 8) 8 9) none of the above

21) What value is printed for the variable x?

  1. -2 7) -3 8) none of the above

Summer I 2006 Page 8 of 9

For the next 2 questions, consider the execution of the following code fragment:

{ int Loop, Count = 3; for (Loop = 2; Loop < Count; Loop--) { Count++; System.out.println( Count ); } System.out.println( Loop ); }

22) What value is printed on the third line of output for the variable Count?

  1. 6 7) 7 8)8 9) none of the above

23) What value is printed for the variable Loop?

  1. -4 7) -5 8)-6 9 ) none of the above

For the next 2 questions, consider execution of the following code fragment:

{ int i, j, count=0, answer = 0; for (i = 0; i < 2; i++) { for (j = 1; j < 3; j++) { count++; answer = answer + i + j; } } System.out.println( answer ); System.out.println( count ); }

24) What value is printed for the variable answer?

  1. 7 8) 8 9) 0 10) none of the above

25) What value is printed for the variable count?

  1. 7 8) 8 9) 0 10) none of the above