SWE 619 Assignment 2
Due Wednesday, September 6, 2023 at 4:30PM


Goal: Contracts

For the second assignment, you'll build a very small piece of Java for a contract with preconditions, transform the contract so that all preconditions become postconditions, and then re-implement appropriately.

Here's the initial contract:

   public static int findDup (int[] a, int[] b)
   // Precondition: a not null;
   //               b not null
   //               There is some index i such that a[i] == b[i]
   //           
   // Postcondition: return the first index i at which a[i] == b[i]
   // E.g. findDup ([7, 13, 5], [5, 13, 5]) = 1
  1. Implement the FindDup method. Remember that checking for violated preconditions is not necessary in the contract model. To emphasize this point, your solution must be minimal. This means that it should not be possible to delete any code and still have your implementation satisfy the contract.

    You should test your implementation; this is an obvious task for the part of your group responsible for checking your solution.

  2. Transform the preconditions into postconditions as discussed in class.
  3. Re-implement.
Grading: