Lab15: Review

Objectives

The Rules

Your instructors will divide you into groups for the duration of the competition. There are several problems in the section below. It is up to you how you wish to divide work, but keep in mind that the winner is decided on quantity and quality.

The Problems

  1. Implement a command-line Java program that emulates the UNIX "cat" program. The cat command takes in several arguments, which are the locations of several files. It then prints the file contents to screen in order. To see how it works, create or find two text files and type "cat file1 file2" in your terminal. For more details on this command, you can read the man page; however, there are many options that are not covered within. Place your implementation in a main() method inside a class called Cat; your implementation should executable by java Cat file file2.
  2. Write a recursive algorithm that takes in an integer parameter n >= 0 and calculates the nth Fibonacci number. Note: Done naively, this can be a very inefficient algorithm. Create a Fibonacci class and place your code inside a static fibonacci() method which takes and returns an int.
  3. Implement a non-cyclic (non-reusable) barrier object. Recall that a barrier is used to prevent threads from proceeding past a certain point of execution until n threads have reached that point. You should create a class named Barrier with a constructor that takes in a single integer that corresponds to the number of threads the barrier handles. Create a wait() method that contains your implementation.
  4. Implement a simple binary search tree for integers. Recall that binary search trees have the property that all nodes in the left child of a parent node are smaller than the parent node and all nodes in the right child of a parent node are larger than the parent node. Your binary search tree should support insertion and search. Create your implementation in a BinaryTree class with a insert() and find() methods. The insert() method should take an integer and insert it into the tree (and return nothing), while the find() method should return true or false, depending on whether or not a specified integer is in the binary tree.

Lab created by: Daniel Tang