Skip to content
Prison management system
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea
.settings
Design
bin
build/classes
nbproject
src
.classpath
.project
Short Bay Prison.iml
build.xml
readme.md

readme.md

Specification

1 Domain

Short Bay Prison is a boutique prison that holds at most 30 prisoners. It has one building with 10 cells on the first floor and 10 cells on the second floor. A cell has an id of the form floor.number, such as 1.7 or 2.10. A cell has one or two bunks; even numbered cells have two bunks and odd numbered cells have one bunk.

A crime has a level, and prisoners at different levels cannot be in the same cell. As an example, assume that these are all the possible crimes with the levels indicated:

  1. drunk, littering, bad hair
  2. fraud, theft, vandalism
  3. murder, arson, assault

A prisoner who committed murder (level 3) cannot be in the same cell as a prisoner with bad hair (level 1). No "master list" of crimes is stored; to make the coding easier, you enter the name and level of the crime when the criminal enters the prison system.

2 System interface

The system menu has six choices. The user enters a single character (upper or lower case) to make a choice. The choices are:

  • N: Add a criminal to the system. A criminal has a name and a unique integer id. The system generates the ids automatically: 1, then 2, then 3, and so on.
  • A: Allocate a cell. A new prisoner is allocated a bunk in the first available cell. The first cell is 1.1 (floor 1, cell 1), then 1.2 ... 1.10, then 2.1, 2.2, and so on. The top bunk is allocated before the bottom bunk.
  • P: Show the prisoner details. Show the prisoner id, name, crime, start and end dates, and the period.
  • C: Show the cell allocations. Show the cell id and the prisoners in the cell. 2 of 6
  • ?: Explain the menu choices.
  • X: Exit the system.

The sentence start date is the day that the criminal enters the prison system (N). The criminal is allocated a cell immediately (A). The sequence is always N and then A so these two actions should really be a single command; I have separated them so they can be given separate marks. The exact IO format can be seen in Assignments/1/io.txt.

3 Dates and periods

All dates and periods are shown in the form day/month/year with no leading zeros, as shown in the provided Date class. The first of February, 2011 is thus shown as 1/2/2011. A period of one year, three months, and six days is shown as 6/3/1. A prisoner with a sentence of 1 day who enters prison on 1/1/2011 has an end date of 2/1/2011; that is, s/he spends one night in jail. The P display for just this prisoner would be:

  • fred drunk: start 1/1/2011, end 2/1/2011, period 1/0/0

To convert a period of the form days/months/years to a number of days, assume that a month has 30 days and a year has 365 days. A period of one year and 3 months is thus converted to a period of 365 + 3 * 30 = 455 days.

The prison date is like a system clock, so it is guaranteed to be a singleton and should be stored as a static attribute in the root class Prison . See Appendix A for the code.

4 Validation

Keep asking for input until a correct value is entered, or the user quits. Check the following:

  • Menu selection can be upper or lower case. Show the choices after an invalid input.
  • Criminal id must match a criminal. Show the ids (or "none") after an invalid input.
  • Can't allocate a cell to a criminal that already has a cell.

5 Simplifying assumptions

Don't run out of cells. Choose your input so this is true.

6 Special requirements

You must use arrays for your data structures. Do not use lists; many people do not know how to use them. The model solution uses all arrays. I apologise if this requirement offends you; I am just trying to be fair. Lists are used in the second assignment.

The input class In

Use the class In to get input. Do not change anything in this class. Just use the class as it exists.

Expected work load

This assignment has been estimated at a load of 18 hours for the average student who has completed all the tutorial and lab exercises. To give you some idea of the code involved, my solution (without classes In or Date ) has about 180 lines of executable code. This count does not include class and method headers, attributes, or getters.

You can’t perform that action at this time.