Some of the OOP lecturers enjoy to play games. One of the games they played a lot was Prison Architect. This assignment is inspired by that game.
Stuxion is a prison facility where prisoners get stuck. Unfortunately, the administration system has failed and is now producing errors. We are here to resolve that problem by creating a new management system.
First a little information about the system you need to create:
Stuxion currently has just 3 small cell blocks, but make sure your system can handle more cell blocks.
Name | Condition | Number of cells |
---|---|---|
The Nerd Cave | hacking | 2 |
The Amsterdam zone | drug | 3 |
The Principals Office | skip | 2 |
Every time a prisoner arrives, a guard asks what the crime was, then looks into the system if a cell block for those crimes is available (by checking if the condition of the cell block is contained in the description of the prioners crime). For example if you have the word “drug” in your crime description then you must go to “The Amsterdam zone” in our example. If no cell block could be found, the system shows an error message.
After finding a suitable cell block, the guards checks if there is a free cell in that block. If thats the case the prisoner can be put into that cell. Otherwise an error message should be displayed.
The system can give the following error message (throw exceptions for this at the right places):
Message | Reason |
---|---|
A cell block can only have 4 cells | This happens when you try to create a cell block with too many cells |
No cell block for crime “??” can be found | This happenss when you try to add a prisoner to the prison that committed a crime that doesn’t have it’s own cell block. Make sure you replace ?? by the actual crime of the prisoner. |
Cell block “??” is full | When you try to add a prisoner to a cell block which has no free cells. Make sure to replace the ?? by the name of the cell block |
We suggest doing the following to build this system:
Prison
only has three methods: addCellBlock
, addPrisoner
and a toString
Feel free to use our dummy code to experiment, or imprison your fellow students: it’s up to you!
Note: The code below contains a few violations of the rules above. It’s your job to find these violations. Adding a few try-catch statements therefore is highly recommended.
public static void main(String[] args) {
Prison prison = new Prison();
try {
//Create cell blocks
prison.addCellBlock("The Nerd Cave", "hack", 2);
prison.addCellBlock("The Amsterdam zone", "drug", 3);
prison.addCellBlock("The Principals Office", "skip", 2);
prison.addCellBlock("Students home", "drinking", 10);
// Create famous prisoners
Prisoner ruud = new Prisoner("Ruud Greven", "hacking the OOP course");
Prisoner tristan = new Prisoner("Tristan Pothoven", "hacking back Ruud Greven");
Prisoner paul = new Prisoner("Paul de Groot", "hacking Tristan and Ruud out of Saxion");
Prisoner janWillem = new Prisoner("Jan Willem Boer", "Baking cake for students");
Prisoner craig = new Prisoner("Craig Bradley", "Trying to do OO properly in VBA");
// Create lesser known prisoners
Prisoner anna = new Prisoner("Anna Alcohol", "taking drugs to program better");
Prisoner clay = new Prisoner("Clay Cannabis ", "smoking drugs");
Prisoner martin = new Prisoner("Martin Meth", "hosting a drugslab");
Prisoner carmen = new Prisoner("Carmen Class", "skipping OOP classes");
Prisoner travis = new Prisoner("Travis Tired", "skipping assignments");
Prisoner john = new Prisoner("John Lennon", "Skipping Imagine classes");
// Add prisoners to the system
prison.addPrisoner(ruud);
prison.addPrisoner(tristan);
prison.addPrisoner(paul);
prison.addPrisoner(janWillem);
prison.addPrisoner(craig);
prison.addPrisoner(anna);
prison.addPrisoner(clay);
prison.addPrisoner(martin);
prison.addPrisoner(carmen);
prison.addPrisoner(travis);
prison.addPrisoner(john);
} catch (IllegalArgumentException iae) {
System.err.println("IllegalArgumentException: " + iae);
} catch (IllegalStateException ise) {
System.err.println("IllegalStateException: " + ise);
}
System.out.println(prison);
}
When the above code is used, the output should look like this. We have intentionally left out any messages with regards to the exceptions. It’s your job to find out what lines throw exceptions (and why).
Cellblock 'The Nerd Cave':
Cell 1) Ruud Greven, Crime: hacking the OOP course
Cell 2) Tristan Pothoven, Crime: hacking back Ruud Greven
Cellblock 'The Amsterdam zone':
Cell 1) Anna Alcohol, Crime: taking drugs to program better
Cell 2) Clay Cannabis , Crime: smoking drugs
Cell 3) Martin Meth, Crime: hosting a drugslab
Cellblock 'The Principals Office':
Cell 1) Carmen Class, Crime: skipping OOP classes
Cell 2) Travis Tired, Crime: skipping assignments
This simplified sequence diagram shows the basic flow of adding someone to the system. Details have deliberately been left vague, showing mainly the interaction between classes.