Docsity

Exam for Introduction to Object Oriented Development | CS 1705, Exams of Computer Science

Toggle sidebar
bg1
CS 1705 Intro to Object-Oriented Development Test 1
Fall 2006 Form A Page 1 of 8
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. Code form A on the Opscan.
• On the opscan: if you are in the 9:05 lecture code group 1; if you are in the 10:20 lecture code group 2.
• 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.
• 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, [ 1705 (integer), 1705.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 25 multiple-choice questions.
Do not start the test until instructed to do so!
Name (print: Last name, First)
VT Email: (print: campus email address)
Circle Lecture section: MW 9:05 MW 10:20
Circle Lab section: Thur 5:00 (McB 118)
Fri 12:10 (Torg 1080) Fri 2:10 (Torg 1080)
Pledge: On my honor, I have neither given nor received unauthorized aid on this examination.
signature
pf3
pf4
pf5
pf8

Partial preview of the text

Download Exam for Introduction to Object Oriented Development | CS 1705 and more Exams Computer Science in PDF only on Docsity!

Fall 2006 Form A Page 1 of 8

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. Code form A on the Opscan.
  • On the opscan: if you are in the 9:05 lecture code group 1 ; if you are in the 10:20 lecture code group 2.
  • 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.
  • 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, [ 1705 (integer), 1705.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 25 multiple-choice questions.

Do not start the test until instructed to do so!

Name (print: Last name, First)

VT Email: (print: campus email address)

Circle Lecture section: MW 9:05 MW 10:

Circle Lab section: Thur 5:00 (McB 118)

Fri 12:10 (Torg 1080) Fri 2:10 (Torg 1080)

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

signature

Fall 2006 Form A Page 2 of 8

1) In order for a Java class to receive event messages as defined in the Eventful Java objectdraw library which of the following must be extended?

  1. WindowToolKit 2) objectdraw

  2. FrameControl 4) AbstractWindow

  3. Canvas 6) none of these

For the next two questions use the following responses:

      1. none of these

2) Consider the following Java objectdraw code segment:

new FramedRect( 10, 10, 100, 100, canvas ); new Line( 60, 110, 60, 10, canvas ); new Line( 110, 60, 10, 60, canvas );

Which of the above figures would represent a scaled down representation of the graphics drawn by the above code?

3) Consider the following Java objectdraw code segment:

new Line( 100, 100, 0, 200, canvas ); new Line( 100, 100, 200, 200, canvas ); new Line( 0, 200, 100, 300, canvas ); new Line( 100, 300, 200, 200, canvas ); new Line( 200, 200, 0, 200, canvas ); new Line( 100, 300, 100, 100, canvas );

Which of the above figures would represent a scaled down representation of the graphics drawn by the above code?

Fall 2006 Form A Page 4 of 8

For the next two questions use the following responses:

      1. none of these

7) Consider the following Java objectdraw code segment:

FilledRect rect = new FilledRect( 10, 10, 100, 100, canvas ); rect.setColor( Color.GRAY ); new Line( 30, 30, 200, 30, canvas ); new FilledOval( 50, 50, 100, 100, canvas ); Text txt = new Text( "Text Label", 110, 110, canvas ); txt.setColor( Color.WHITE );

Which of the above figures would represent a scaled down representation of the graphics drawn by the above code?

8) Consider the following Java objectdraw code segment:

FilledRect rect = new FilledRect( 10, 10, 100, 100, canvas ); rect.setColor( Color.GRAY ); rect.sendToBack(); Line lin = new Line( 30, 30, 200, 30, canvas ); lin.sendBackward(); FilledOval oval = new FilledOval( 50, 50, 100, 100, canvas ); oval.sendToBack(); Text txt = new Text( "Text Label", 110, 110, canvas ); txt.setColor( Color.WHITE ); txt.sendToBack();

Which of the above figures would represent a scaled down representation of the graphics drawn by the above code?

Text Label

Text Label

Fall 2006 Form A Page 5 of 8

9) Consider the following Java objectdraw code:

Location origin = new Location( 0, 0 ); Location originAlias = origin;

boolean ques9 = ( origin == originAlias );

What value is assigned to the variable ques9 by the above code?

  1. true 2) false 3) null 4) undefined

10) Consider the following Java objectdraw code:

Location origin = new Location( 0, 0 ); Location unit = new Location( 1, 1 ); unit.translate( -1, -1 );

boolean ques10 = ( origin == unit);

What value is assigned to the variable ques10 by the above code?

  1. true 2) false 3) null 4) undefined

11) Consider the following Java objectdraw code:

Location origin = new Location( 0, 0 ); Location unit = new Location( 1, 1 ); unit.translate( -1, -1 );

boolean ques11 = origin.equals(unit);

What value is assigned to the variable ques11 by the above code?

  1. true 2) false 3) null 4) undefined

Fall 2006 Form A Page 7 of 8

21) Consider the following Java code:

int A = 0, D = 5; if (R <= T) D = A - 1; else A = 1;

Which of the following code fragments is equivalent to the code above? "Equivalent" means that each code fragment would assign the same values to A and D as the code given above, no matter what the initial values for the variables R and T were.

  1. int A = 0, D = 5; 2) int A = 0, D = 5; if (R > T) if (R >= T) A = 1; A = 1; else else D = A - 1; D = A - 1;

  2. int A = 0, D = 5; 4) int A = 0, D = 5; if (R > T) if (R < T) A = 1; A = 1; if (R <= T) if (R > T) D = A - 1; D = A - 1;

  3. all of the above 6) 1 and 2 only 7) 1 and 3 only

  4. 2 and 4 only 9) none are equivalent

22) What is the value printed for the variable delta if the following code is executed?

int delta = 0, x = 3; if ( x / 2 == 1 ) delta = delta + x; x--; if ( x / 2 == 0 ) delta = delta + x; x--; if ( x / 2 == 0 ) delta = delta + x;

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

  1. 4 6) 5 7) 6 8) None of the above

23) Consider the following Java code:

int i = -1, j = 0, k = 1;

boolean b = ( ( i <= j ) || ( k >= j ) );

How many relational operator comparisons are executed by the above code?

  1. 0 5) none of these

Fall 2006 Form A Page 8 of 8

The area of a triangle with sides A, B and C is given by Heron's Formula:

Area = S S ( − A )( S − B )( S − C ) where S = ( A + B + C ) / 2

Given the following Java variable declarations:

double area, s, a, b, c;

24) Assume that all of the above variables have been assigned values. Which one of the following two-line code segments accurately describes the correct computation of the area of the triangle represented by sides with lengths equaling the values stored in the variables a, b & c?

  1. s = ( a + b + c ) / 2; area = sqrt( s * (s - a) * (s - b) * (s - c) );

  2. s = ( a + b + c ) / 2; area = Math.sqrt( s (s - a) (s - b) (s - c) );

  3. s = ( a + b + c ) / 2; area = sqrt( s (s - a) (s - b) (s - c) );

  4. s = ( a + b + c ) / 2; area = Math.sqrt( s * (s - a) * (s - b) * (s - c) );

  5. None of the above

Suppose a triangle has sides A, B and C, and assume C is the longest side, say:

Then:

Given the following Java variable declarations:

double a, b, c; boolean right;

25) Assume that all of the above variables have been assigned values. Which one of the following expressions correctly determines if the triangle represented by sides with lengths equaling the values stored in the variables a, b & c is a right triangle?

  1. right = ( c^2 = (a^2 + b^2) );
  2. right = ( Math.exp(c, 2) = (Math.exp(a, 2) + Math.exp(b, 2) );
  3. right = ( Math.pow(c, 2) == (Math.pow(a, 2) + Math.pow(b, 2) );
  4. right = ( Math.sqr(c, 2) == (Math.sqr(a, 2) + Math.sqr(b, 2) );
  5. None of these

Triangle is: If: Acute C^2 < A^2 + B 2 Right C^2 = A^2 + B 2 Obtuse C^2 > A^2 + B 2

A

B

C