Midterm Review


Work with your assigned partner to answer the following questions and complete the following exercises.

Questions

  1. Define abstraction. How can it be applied to procedures and data?
  2. What is polymorphism?
  3. What is substitutability?

Tuple

Consider this UML:



  1. Write out the first line of the class definition.
  2. How are generics used?
  3. Is there any overriding or overloading happening?
  4. List out the pseudocode for 5 tests of the Tuple class

Shapes

Convert the following class headers (first line) into UML:

public abstract Shape implements Comparable

public Rectangle extends Shape

public Circle extends Shape

ArrayList

  1. Write out the pseudo code for the add method.
  2. Write out the pseudo code for the remove method.
  3. Write out the pseudo code for the addAt method.

Complexity Analysis

Determine the complexity of the following Java methods:

  1. public static boolean hasDuplicate(double[] array) {
        boolean duplicateFound = false;
        
        if (array != null && array.length > 1) {
            int i = 0;
            int n = array.length;
            
            while (i < n - 1 && !duplicateFound) {
                int j = i + 1;
                
                while (j < n && !duplicateFound) {
                    if (array[i] == array[j]) {
                        duplicateFound = true;
                    }
                    j++;
                }
                i++;
            }
        }
        
        return duplicateFound;
    }
    
  2. public static int longestIdenticalRun(double[] array) {
        int maxRun = 0;
        
        if (array != null && array.length > 0) {
            int i = 0;
            int n = array.length;
            
            while (i < n) {
                int currentRun = 1;
                int j = i + 1;
                
                while (j < n && array[j] == array[i]) {
                    currentRun++;
                    j++;
                }
                
                if (currentRun > maxRun) {
                    maxRun = currentRun;
                }
                
                i = j; 
            }
        }
        
        return maxRun;
    }
    
  3. public static int foo(int steps)
    {
       int limit = 1;
       int sum = 0;
    
       for(int i = 0; i < steps; i++)
       {
          limit = limit * 2;
       }
    
       for(int i = 0; i <= limit; i++)
       {
          sum = sum + i;
       }
    
       return sum;
    }
    

This page was last modified on 2026-10-05 at 17:14:03.

Copyright © 2018–2026 George Fox University. All rights reserved.