Review questions for the final

 

True or False:

  1. The H in HTML stands for Header information. ( True / False )?
  2. The HTML tag <LI> is used to indicate the start of large italic text. ( True / False )?
  3. In object-oriented programming, methods provide the functionality ( True / False )?
  4. Using the "binary search" guessing strategy discussed in the notes and in class, we can find any number between 0 and 100 in 2 guesses ( True/False )? 
  5. Text can read from the user and written to the screen in an applet using a TextFieldTrue/False )?
  6. We want to connect 100 computers using ethernets that can connect 4 computers together. If each computer has 2 network interfaces, we can connect all of the computers with 10 networks ( True/False )? 
  7. The if statement allows a program to do or not do something depending on the answer to the if clause ( True/False )?
  8. A good password should use long words in the dictionary. ( True/False )?
  9. Public Key Encryption uses the same key for both encryption and decryption. ( True/False )?
  10. A recursive algorithm should have some sort of base case where the solution can be given without any further recursive calls. ( True/False )?
  11. You need to add an array in the init method. (True/False)

Random quick questions:

  1. What do the import lines do at the beginning of every java program?
  2. What method gets called when the user clicks a button?
  3. What is wrong with the following statement (imagining that s has already been declared as a String)?                   s.setText(hello world)                          
  4. How do you declare an array?
  5. What values can a Boolean have?
  6. What is the purpose of the following line in an actionPerformed function?                                                           Cause event = e.getSource();

String manipulation:

    1. Write a subroutine that returns the 3 middle letters of a word with an odd number of letters, or the 2 middle letter of a word with an even number of words.
    2. Write a subroutine that will take in a string and  return a string with the letters backwards. (example: if you pass it in “hell” it will return “lleh”)

Grammar:

  1. Show how to parse the following Java statement:
2.             total = freq + 1;

Be sure to show every step and give the number of each rule that you are using.

 
 
 
 
 
 
 
 
 

Here are the rules you may use

    1. <name> ==> any string of alphanumeric symbols that begins with a letter
    2. <statement> ==> <name> = <expression> ;
    3. <statement> ==> <name> = new <class>(<arguments>);
    4. <statement> ==> <name>.<method>(<arguments>) | <method>(<arguments>) ;
    5. <arguments> == possibly empty list of <expression>s separated by commas
    6. <expression> ==> <string-expression> | <int-expression> | <oth-expression>
    7. <string-expression> ==> <string-expression> + <string-expression>
    8. <string-expression> ==> <string>
    9. <string> ==> " any sequence of characters "
    10. <string> ==> <name>
    11. <int-expression> ==> <name>
    12. <int-expression> ==> <int-expression> <op> <int-expression>
    13. <int-expression> ==> <pos-int> | - <pos-int>
    14. <pos-int> ==> any sequence of digits

15.  <op> ==> + | - | * | / | %

Recursion:

  1. The sum of N numbers in an array can be computed as follows: Add the first N-1 numbers, and then add that sum to the last number. Use this method to write a recursive function for summing an array. Your solution should NOT involve a while loop. 

Graphics:

  1. Write the code to draw a red triangle with vertices (20,20), (110, 20), and (65, 80). Assume that everything has been declared and is ready to go. This should take four lines of code. Assume the graphics class you are working with is named g.

Binary:

  1. Find the decimal forms of following binary numbers: 
    1. 01000001
    2. 11111111
  2. Find binary forms of the following decimal numbers:
    1. 15

b.      7

Running time:

  1. Assume we have yet another program which we run for several small values of N. We notice that every time we increase N by one, it takes 10 times as long to run. Circle those of the following terms that we might reasonably use to describe the behavior of the program and it's underlying algorithm.
         polynomial               exponential              intractable                logarithmic               difficult-for-computers              made-for-computers
  1. Assume the information in a telephone book has been placed in a computer memory, alphabetized like in a real phone book. We would like to search for a name. Which algorithmic behavior could we expect from a well written search program using a binary search? (N is the number of entries in the phone book.) 
    1. (Logarithmic time (t = C * log N))
    2. Quadratic time (t = C * N2 )
    3. Linear time (t = C * N)