CPEN 221A · 2025 lab archive

Lab 6: Representation Invariants and the JobManager

2025 archive

Jump to a lab section

Overview

In Lab 5, you designed and programmed your own implementation of the JobManager abstract data type (ADT). In this lab, you're given a buggy implementation of the JobManager, and you're tasked with formulating its representation invariant (RI) and programming this RI in the form of a checkRep method, which ensures all conditions of the RI are met. Using your checkRep method, you should find & fix all the bugs in the given implementation. You are not allowed to change the representation (fields) of the implementation in any way.


The JobManager ADT Operations (Same as Lab 5)

A JobManager is seeded with n (the number of jobs it is managing). Each of these n jobs are initially “unassigned” (i.e., not assigned to a robot). One can then add Robots, assign jobs to the Robots, and move jobs among the Robots.

The principal operations that the JobManager ADT supports are as follows:


Tasks

You are tasked with completing the following. You are not allowed to change the representation (fields) of the provided implementation in any way.

  1. Implement the checkRep() method to throw an AssertionError if and only if the representation invariant (RI) for the provided implementation of JobManager is violated.

    • You cannot use the assert keyword in checkRep(). Instead, you must throw new AssertionError() if the representation invariant is violated. Otherwise, you will not pass the tests on PrairieLearn.

  2. Run the provided test suite for checkRep() in CheckRepTests.java

  3. Once you have checkRep() working, call this.checkRep() before all exit points in other methods like assignJobs.

  4. Now, you can use checkRep() to help you find bugs in the implementation.

    • Hint: Look at which test cases were previously passing but started failing right after you added calls to checkRep() in the relevant methods.

  5. Fix all the bugs in the implementation, and ensure you’re passing all provided test cases in JobManagerTests.java .

  6. Once you’re confident in your solution, submit your code on PrairieLearn.

  7. Answer the questions in the second part of the lab on PrairieLearn. (Or you can start with this if you like too.)


Grading

You will answer some questions on PrairieLearn and you will submit your implementation to PrairieLearn as well. This programming task is worth 6 points and the other questions on PrairieLearn are worth 3 points.