Assignment 1

We take an incremental approach to understanding Java classes. The first step is to view classes as modules and view static methods as functions. After this step, we are able to write many C programs in Java.

  1. Write a program that prints a staircase where the number of steps is changable.
    
                          +---+
                          |   |
                      +---+---+
                      |   |   |
                  +---+---+---+
                  |   |   |   |
              +---+---+---+---+
              |   |   |   |   |
              +---+---+---+---+
    
  2. Implement the array module (class) as specified below and write a test module (class) to test it. Notice that the goal of this exercise is to let C programmers get used to the Java language. In the step, we will learn how to write OOP style programs.
    
    public class Array {
        static int[] copyArray(int[] orig){
            // return a copy of orig
        }
        static void selectionSort(int[] a){
           // sort a using the selection sort algorithm
        }
        static void quickSort(int[] a){
           // sort a using the quick sort algorithm
        }
        static boolean linearSearch(int[] a, int x){
           // search x in the array a using the sequential search algorithm
        }
        static boolean binarySearch(int[] a, int x){
           // search x in the array a using the binary search algorithm
           // assume a is sorted in acending order
        }
    }