CIT 591 Final Exam, Fall 2008 Name ______________________________
  1. (5 points) Write the complete header for a program's main method.



  2. (5 points) Write a complete enum class for the days of the week. Use three-letter abbreviations for the days.




  3. (15 points) Consider the following method (defined in a class WordPlay):
        public static boolean isVowel(char ch) {
            return "aeiouAEIOU".indexOf(ch) > 0;
        }
    1. Write a complete JUnit test method for the isVowel method.







    2. Write a complete Javadoc comment, using the correct syntax, for the isVowel method.





    3. Why is making this method static the correct thing to do?






  4. (5 points) A class has a private instance int[ ] variable named position. Write a getter method for position.




  5. (5 points) Two Book objects are "equal" if they have the same Isbn, where Isbn is an instance variable of type String. Write a correct and complete equals method for Book objects, and indicate (with a @ annotation) that it overrides the inherited equals method.











  6. (15 points) True or False:

    1. _____ Every class always has a constructor.

    2. _____ If Inner is an inner class of class Outer, then objects of type Inner can be used only within class Outer.

    3. _____ A static method may not be private.

    4. _____ A method that returns void cannot be JUnit tested.

    5. _____ Declaring (but not defining) a JPanel object does not allocate any space.

    6. _____ An instance method may have the same name as an instance variable.

    7. _____ A method that takes a double parameter can only be called with a float or double argument.

    8. _____ A constructor may call another constructor with one of the keywords this and super.

    9. _____ An abstract class may have an explicit constructor.

    10. _____ An interface may declare a constructor.

    11. _____ All enum constructors are automatically private.

    12. _____ An interface can implement another interface.

    13. _____ If the same variable name is used in several methods, it should be an instance variable.

    14. _____ When printing an object, System.out.println calls the object's toString() method.

    15. _____ Scope rules apply within a class; access rules apply between classes.

  7. (5 points) String s contains only digits. Write a single assignment statement to convert this string to an integer and assign it to variable n.


  8. (5 points) Write a single print statement to print true if the double variable x is greater than 100.0, and print false otherwise.



  9. (5 points) Write a single print statement to print the value of x if it is positive, and print the value of y otherwise.



  10. (5 points) Draw a vertical line, |, everywhere in the following statement that the style rules specify there should be a space. (I've put one in the only location required by the syntax rules.)

               f  o  r  (  i  n  t    |    i  =  0  ;  i  <  =  1  0  ;  i  +  +  )  s  u  m  +  =  i  ;

  11. (10 points) Give two reasons why it is a good idea to write tests before writing the code to be tested.





  12. (5 points) What should a constructor do, and what shouldn't it do?





  13. (5 points) For whom should you write Javadoc comments, and what kind of information should you convey?




  14. (5 points) For whom should you write internal (// and /*...*/) comments, and what kind of information should you convey?




  15. (5 points) Variable rabbit holds an object of type Animal, which implements Runnable. Write the code to start rabbit executing in a new Thread.