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:
- 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.
- Write an iterative method to calculate a^n
- What is the Big(O) complexity of each 2^n algorithm
- What is the Big(O) best case?
- What is the Big(O) worst case?
- Write an application that prints out the command line arguments the user entered
- Write a Java interface: “Sellable” that has some methods:
- String getDescription()
- getPrice()
- setPrice()
- char condition = getCondition()
- Write a class UsedCar that implements Sellable
- Write a class NewCar that implements Sellable
- 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.
- Do lab 4 for Exceptions practice! ☺
- List backed by an array
- How do I add/remove/insert into the List?
- Write the code for each (see slides from class for examples)