





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






Summer I 2006 Page 1 of 9
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.
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.
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?
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?
onMouseClick 2) onMouseDrag
onMouseEnter 4) onMouseRelease
onMouseExit 6) onMouseMove
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 2) 0
canvas.getHeight() 4) canvas.getWidth()
canvas.getSize() 6) canvas.getX()
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?
canvas.getY() 2) canvas.getX() + canvas.getY()
canvas.getHeight() 4) canvas.getWidth()
canvas.getSize() 6) canvas.getX()
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?
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?
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);
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?
21) What value is printed for the variable x?
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?
23) What value is printed for the variable Loop?
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?
25) What value is printed for the variable count?