CS211 MIDTERM Practice Problems
Fall 2007

** Don’t forget to know the Unix commands!!! **

** Look through the Midterm Review on the website -- the practice problems will help with coding, but there are other things you need to know!!! **

Practice Problems:

  1. Write a recursive method to calculate a^n.  calc(int a, int n). For example, if a=10 and n=2 you are calculating 10^2 = 100.
  2. Write an iterative method to calculate a^n
  3. What is the Big(O) complexity of each 2^n algorithm
    1. What is the Big(O) best case?   
    2. What is the Big(O) worst case?
  4. Write an application that prints out the command line arguments the user entered
  5. Write a Java interface: “Sellable” that has some methods:
    1. String getDescription()
    2. getPrice()
    3. setPrice()
    4. char condition = getCondition()
  6. Write a class UsedCar that implements Sellable
  7. Write a class NewCar that implements Sellable
  8. Write a method that takes an array of Sellable and uses the new for loop “foreach” loop to print out the array. Test it by creating the array having a mix of UsedCar and NewCar in it.
  9. Do lab 4 for Exceptions practice! ☺
  10. List backed by an array
    1. How do I add/remove/insert into the List?
    2. Write the code for each (see slides from class for examples)