CIT 591 Final Exam

Name __________________________________
  1. (28 points) In this question you will write a complete Java program that repeatedly (1) reads in an integer from the user, (2) prints "Buzz" if the integer is divisible by 7, otherwise prints the integer, and (3) quits when a negative number or zero is entered.

    Include all necessary braces, semicolons, etc. so that your answers, taken together, are a complete, runnable Java program.

    1. Write the Java line that declares your program is in a folder named buzzer.


    2. You will need a Scanner. Import the appropriate class from java.util.


    3. Write a Javadoc comment that, using the appropriate tag, names you as the program author.



    4. Declare the class. Name it Buzz.


    5. Write the method header for the main method.


    6. Create a Scanner object to read input from the keyboard, and save it in a variable.


    7. Declare an integer variable, and use the Scanner to read in a value for it from the user.


    8. Start a loop that will keep running as long as the value you got from the user is positive.


    9. Call a method buzz (which you will write below). Pass it the integer as a parameter.


    10. Read in the next integer.


                  }
            }
        
    11. Write the header for the buzz method, which takes one integer as a parameter.


    12. Test if the parameter is divisible by seven.


    13. Print "Buzz" if the above test passes.


    14. Print the number itself if the above test fails.



                          }
                }


  2. (3 points) In the above program, should the method buzz be marked static? Why or why not?







  3. (4 points) Assume you are inside a class Point with two instance variables, double x and double y.

    1. Write a constructor for Point which takes two parameters, x and y, and sets the corresponding instance variables.






    2. Write a second constructor for Point which takes no parameters, and uses the first constructor to set both x and y to zero.







  4. (2 points) When a variable is declared within the body of a method, what is the scope of that method?
  5. (2 points) What does a break statement break out of? (Give a complete answer, not just one thing.)



  6. (2 points) If a method is overloaded, what must be different between different versions of the method? (Be specific.)





  7. (2 points) What is the very first thing that any constructor does?




  8. (2 points) What does the optional @Override annotation do?




  9. (4 points) The ++ operator is supposed to add 1 to a variable. Write a complete unit test method, containing one test, to show that it works.







  10. (2 points)
    1. What is the abstract superclass of the Exception class?



    2. What is the subclass of Exception used for unchecked exceptions?



  11. (6 points) Name each of the following layout managers:
    layouts

  12. (6 points) What are the two ways of creating a new thread?
    a. Extend what class?


    d. Implement what interface?


    b. Provide what method?


    e. Provide what method?


    c. Start the thread running?


    f. Start the thread running?



  13. (6 points) Write statements to do the following (each should be a single line):

    1. Create a button named okButton, with the text OK.



    2. Assume you have an ActionListener class named MyActionListener. Create an instance of this class and attach it to the okButton.



    3. Assume you have a JPanel named buttonPanel. Put the okButton into this panel.




  14. (4 points) When using Observer/Observable,

    1. What two statements should the Observable instance execute to indicate that something has changed?




    2. What method must the Observer instance provide? Give the complete signature.




  15. (2 points) What does the Javadoc program do with the first sentence of a Javadoc comment?




  16. (2 points) What kind of a Reader will allow you to read a file one line at a time?




  17. (5 points) Write a complete method named nargs that takes any number of integer arguments, and returns the integer count of how many arguments it was given (Example: nargs(10, 20, 30) should return 3).








  18. (4 points) What are the two methods provided by every Iterator?




  19. (4 points) Declare and define a Map variable named counts, whose keys are Strings and the values associated with those keys are integers.



  20. (6 points) What is the git command to:

    1. Put all the files in this directory under the control of git



    2. Copy a git repository from a given URL



    3. Merge changes from a remote repository into your local repository




  21. (4 points) charBlock is a two-dimensional array of printable characters. Write statements (not a complete method) to print out the array.