CSSE 373 Formal Methods in Specification and Design

HW10

Purpose: practice specifying classes using JML and checking specifications using ESC/Java2

Please note: The JML tool chain is very much research quality. There are improved versions of the tools, but they have complex installation requirements. So, we’re using a simpler, older version of the tools, even though they are less robust. I hope that this will minimize installation pain while still letting us get a feel for what the future may hold as the tools improve.

  1. Keep track of how much time you spend on this assignment. Please put in your best effort, but don’t spend too much time battling the tools. Unlike previous assignments you will submit your answers by committing annotated Java files at the end of the homework.
  2. Install the Mobius PVE, create a new workspace, and a new project (with ESC/Java nature) by carefully following these instructions.
  3. Copy the following two Java class declarations into your new project:

  4. In general terms, your task is to annotate the two classes with JML specifications using the Design-by-Contract style. You’ll add:

    For this assignment, you do not need to specify assignable clauses, though you certainly may.

    1. Specify and fix the Amount class first. There are additional instructions in the comments at the beginning of that file. Note that the code has some subtle bugs in it. Part of your challenge is to determine whether your specification is wrong or the code is wrong. Your final solution should be concisely specified and correctly implemented.
    2. Next specify and fix the Bag class. Like Amount, there are additional instructions in the comments. Unlike Amount, I give you less information about what invariants should hold for the class. Use the method names and the general idea of a multi-set to come up with an appropriate specification.

    Some crucial hints:

  5. Copy your annotated Amount.java and Bag.java files to the appropriate HW folder in your individual subversion repository for this course. Add and commit them. You do not need to turn in a pdf for this assignment.

This assignment is based on one by Erik Poll at Radboud University Nijmegen.