CPS 4 Summer 2003 : Quiz 3


Name: Grader: Score:

Syntax

  1. Which of the following could legitimately be used as a name in Java?
    1. luke
    2. jabba_the_hut
    3. PrincessLeia
    4. Han Solo
    5. obi-wan
    6. 3PO
    7. R2D2
    8. c3po
       
  2. Identify the syntax error in each of the following statements.
    1. Box small = new Box(50 25 50 100);
    2. Thing mine = new Thing;
    3. Example new = new Example();
    4. GP.Attributes.Angle start = 100;
       
  3. State whether each of the following is true or false.
    1. All variables must be given a type when they are declared.
    2. Java considers the variables number and NumBEr to be identical.
    3. A variable can refer to more than one object at the same time.

Ordering Statements

  1. Assume that the following statements are executed, in order.
    double a = 5;
    double b = 7;
    double c = 3;
    double d = 0;
    a = b;
    c = d;
    a = d;
    What is the value of a?
    Of b?
    Of c?
    Of d?
     
  2. Which of the follow happens when the following statement is executed
    GP.Attributes.Colors.Black b = new GP.Attributes.Colors.Black();
    1. A new black oval is drawn
    2. The name b is given to an object that represents the color black
    3. The last shape created is colored black
    4. All of the above
       
  3. In what order do the following statements need to be written for oval to properly be positioned at (100, 100)?
    1. GP.Attributes.Coordinate center = new GP.Attributes.Coordinate(100,100);
    2. oval.SetPosition(center);
    3. GP.Shapes.Oval oval = new GP.Shapes.Oval();

Check your Understanding

  1. Explain, briefly, why it is necessary to have different types of variables (i.e., string versus double versus GP.Shapes.Oval).
     
     
     
     

     
     
     
     
     
  2. Explain, briefly, when it is necessary to explicitly assign a name to an object created using new. In other words, what purpose does naming an object serve?


     





Extra Credit

Given the two balanced scales on the left, how many 'C' balls does it take to balance one 'A' ball?