CIT 591 Final Exam, Fall 2011 Name ____________________________________

Please keep all answers short and to the point. Do not add information that is not asked for; you will not gain points, but you may lose points if you get it wrong. If the question asks for a statement, write a statement, not a function. If the question asks for a function, write a function, not a class. In short, read the question!

  1. (10 points) In the following program,
    1 public class MyClass {
    2     private static int a = 10;
    3     private int b = 20;
    4     
    5     public static void main(String[] args) {
    6         System.out.println(  ?  );
    7         int c = 30;
    8         System.out.println(  ?  );
    9         for (int d = 0; d < 10; d++) {
    10             System.out.println(  ?  );
    11             int e = 50;
    12             System.out.println(  ?  );
    13             new MyClass().run();
    14         }
    15     }
    16 
    17     private void run() {
    18         System.out.println(  ?  );
    19     }
    20 }
    tell which of the variables (a, b, c, d, e, args) may be printed by each of the println statements:

    1. println at line 6: ____________________________________________

    2. println at line 8: ____________________________________________

    3. println at line 10: ____________________________________________

    4. println at line 12: ____________________________________________

    5. println at line 18: ____________________________________________


  2. (5 points) For each of the following, write either "can" or "cannot" in the blank.

    1. Eclipse ___________ create a unit test class, complete with stub test methods.

    2. Eclipse ___________ display the Javadoc for both built-in functions and functions that you write.

    3. Eclipse ___________ find references in other classes to an instance variable declared in this class.

    4. Eclipse ___________ reformat your code to use tabs instead of spaces.

    5. Eclipse ___________ generate an equals method for objects of a class that you have defined.



  3. (5 points) What is the signature of a Java method? Give a precise definition, not an example.









  4. (4 points) Test-driven development (TDD) encourages better code, not just code with fewer bugs. List two ways in which code written using TDD is likely to be better.

    1.  



    2.  



  5. (5 points) (True or False) In pair programming,

    1. __________ The navigator should tell the driver what to type.

    2. __________ The navigator should think ahead and keep a "big picture" view.

    3. __________ The navigator should tell the driver whenever he/she makes a typing error.

    4. __________ The driver and navigator should switch roles frequently.

    5. __________ The driver should talk aloud about what the code he/she is entering is supposed to do.


  6. (5 points) A variable obj has been declared as Object obj; but you happen to know that it contains a String. Write an expression to return the length of the string in variable obj.





  7. (5 points) A class Car has a constructor Car(String make, String model, int year). Write another constructor for Car that takes make and model parameters, and calls the first constructor with those values and a default value of 2011 for the year.








  8. (5 points) Draw a picture to show the various areas of a BorderLayout. Label each area.












  9. (5 points) True or False: When you override a method:

    1. ______ You must use the same function name.

    2. ______ You must use the same access (public, protected, package, or private).

    3. ______ You must use the same return type.

    4. ______ You must use the same parameter types.

    5. ______ You must use the same parameter names


  10. (10 points) If int x = 100, what is the value of each of the following expressions?
    x / 30  
    x % 30  
    x == 99 ? 5 : 7  
    x & x  
    ~x  
    x << 2  
    x >> 2  
    x <<< 2  
    x >>> 2  
    x ^ x  


  11. (5 points) Write a loop to compute the first power of 2 that exceeds one million (1,000,000) and save it in a variable named bigPower.














  12. (5 points) A movie theater charges different prices for small children, students, adults, and seniors. Write an enum to list (enumerate) these types of customer.








  13. (5 points) Java supplies a genericized class ArrayList. Declare and define a variable named people that holds an ArrayList, where every value in the ArrayList must be of type Person.







  14. (5 points) Assume quitButton is a JButton that has been created and displayed. Write code to call Java's exit(0) method when this button is clicked, using either a member class or an anonymous inner class (your choice).












  15. (5 points) What does it mean to say that an exception is checked or unchecked?








  16. (4 points) Complete the following sentence:
             A method should be made static if...





  17. (4 points) What is the DRY principle, and how does it apply to data?







  18. (4 points) What are the four conditions for serializing an object?



    1.  


    2.  
    3.  


    4.  



  19. (4 points) In MVC you want the Model to be independent of the Controller and the View. To support this, Java

    provides you with the ____________________ interface and the ___________________ class.