I am working on an assignment in java where I have Prisoner
class which have date of offence (dd-MM-yyyy) localDate format, name and years in prison. I also have Cell
class where I have to add prisoners in the cell.
I have to make a method to show which Prisoner
should be release first from the Cell
.
Unfortunately, I have no idea how to do that. I already made a method for adding the prisoners in the cell and I use HashSet but I have not idea how to calculate who should be released first.
This is my code for adding the prisoners
public Boolean addPrisoner(Prisoner prisoner) {
if (this.prisonerList.size() <= this.cellSize) {
return this.prisonerList.add(prisoner);
}
return false;
}
Have your prisoner calculate his or her own release date (in real life this might tempt to calculate fraudulent release dates, but as long as you write the method, it’s OK in a Java program). For example:
Now
Collections.min
can find the prisoner having the earliest release date: