CS 4773 Object Oriented Systems


Midterm Exam Solutions

  1. Problem 1
       public class Point3 {
          private int x;
          private int y;
          private int z;
    
          public Point3(int x, int y, int z) {
             this.x = x;
             this.y = y;
             this.z = z;
          }
    
          public int get_x() {
             return x;
          }
        
          public int get_y() {
             return y;
          }
        
          public int get_z() {
             return z;
          }
    
          public void set(int x, int y, int z) {
             this.x = x;
             this.y = y;
             this.z = z;
          }
       }
    
  2. Problem 2
    5 points follow:
    0: 0 -1
    1: 1 0
    2: 2 1
    3: 3 2
    4: 4 3
    5 points follow:
    0: 0 -1
    1: 1 0
    2: 2 1
    3: 9 2
    4: 4 3
    5 points follow:
    0: 0 -1
    1: 9 2
    2: 2 1
    3: 9 2
    4: 4 3
    5 points follow:
    0: 0 -1
    1: 200 300
    2: 2 1
    3: 200 300
    4: 4 3
    5 points follow:
    0: 0 -1
    1: 500 700
    2: 2 1
    3: 500 700
    4: 4 3
    
  3. Problem 3

    Key points:

    class info_class {
       String name;
       int SSN;
    
       info_class(String name, int SSN) {
          this.name = new String(name);
          this.SSN = SSN;
       }
    }
    
    class information {
       info_class[] info;
       int info_size;
       int max_size;
    
       information(int max_size) {
          this.max_size = max_size;
          info = new info_class[max_size];
          info_size = 0;
       }
    
       int insert(String name, int SSN) {
          if (info_size == max_size) return -1;
          info[info_size] = new info_class(name,SSN);
          info_size++;
          return info_size;
       }
    
       info_class find_name(String name) {
          for (int i=0;i< info_size; i++)
             if (info[i].name.equals(name))
                return info[i];
          return null;
       }
     
       void delete(int SSN) {
          int i;
          for (i=0;i< info_size;i++)
             if (info[i].SSN == SSN) {
                info_size--;
                break;
             }
          for ( ; i< info_size; i++)
              info[i] = info[i+1];
       }
     
       void show() {
          String ssn;
          System.out.println("Size is "+info_size);
          for (int i=0;i< info_size;i++) {
             ssn = info[i].SSN + " ";
             while (ssn.length() <  13) ssn = " " + ssn;
             System.out.println(ssn+info[i].name);
          }  
       }
     
    }
    
    Open up a Java console and then click Here to run an applet that uses these classes. The output will appear in the Java console.


Documenting Java programs with javadoc

javadoc will create html files with documentation like the java online documentation.

All you need to do is to insert comments into your code in the right format.

Here is an example entry that is generated.

To have javadoc create documentation for a package:

Several html files will be generated. Here is the javadoc documentation

Here is the JOTSA documentation created so far.

So far, a first pass has been made on the following: