Chris Pollett >
Old Classes >
PIC20B

   ( Print View )

Enrollment info

Course Info: Homework Assignments: Practice Exams: PIC:
                            












PIC 20B Practice Midterm

What to expect from the real thing:

The real midterm will be in class, closed book, closed notes and have five
problems of approximately the same difficulty as those below. Each problem
will be worth 5pts. One of the problems below is guaranteed to be on
the actual midterm.

1. Calculate the value of the following expression: (a) 22 ^ 34,
   (b) 86 & 255, (c) 32 | 16, (d) 86 << 3, (e) 16>>>3.

2. Write a function with prototype Vector Cards() which uses the class
   Random to generate a Vector of Integers which are a permutation of the
   numbers 1-52. (i.e., a shuffled deck of cards).

3. Write a function void DecimateFile(String fileName) which opens
   fileName which we assume contains only int's. It then sets
   every 10th int to 0 and closes the file.

4. Use the class StringTokenizer and Stack to write a function
   boolean IsParenthesized(String expr) which returns true
   iff expr is properly parenthesized. expr is properly parenthesize
   if it does not contain (,) or if it does contain them and it is
   of the form expr1(expr2)expr3 where expr1, expr2, expr3 are properly
   parenthesized. expr1, expr2, expr are allowed to be empty.

5. Write a Java program which prints to System.out all the file names of
   files in the current directory.

6. Write a program which uses a JFileChooser to get a filename from the
   user. It then reads that file in and writes it out gzipped to
   stuff.zip

7. Consider String s = "hi"; in the expression s+="!"; Explain how this
   is implemented with StringBuffers in some compilers.

8. Show how to delecte and insert a character at location 10 in a
   StringBuffer buf.

9. Distinguish Java Enumerations and Java Iterators.

10. Explain how to insert, remove and find elements in the class
    HashTable and TreeMap.