Have to do this for a college Java project
http://homepage.eircom.net/~iandowney/m2pra.htm. Basically I have everything done except the last bit of PartC: "The report should be capable of being provided in order of prison number or in order of surname." I have no clue how to go about this. I've looked at javadocs and I know there are things like Arrays.sort()., but I couldn't figure out how to do it. Can you please explain how to do it? Thanks
public class prisonManager3
{
public static void main(String[]args)
{
System.out.println(" ");
System.out.println("WELCOME TO PRISON MANAGER");
System.out.println(" ");
//create array of prisoners
prisoner [] inmate = new prisoner[3];
System.out.println("Enter details for each inmate.");
for(int i=0;i<inmate.length;i++)
{
inmate[i] = new prisoner();
//enter inmate details
inmate[i].setName();
inmate[i].setAge();
inmate[i].setSentence();
inmate[i].setNumber();
inmate[i].setCellnum(i);
System.out.println("Inmate Recorded");
}
int maxAge = 0, minAge = 999, maxSentence = 0, sentenceCount = 0, youngestCount = 0;
//check for other details
for(int i=0;i<inmate.length;i++)
{
if(inmate[i].age > maxAge)
{
maxAge = inmate[i].age;
}
if(inmate[i].age < minAge)
{
minAge = inmate[i].age;
youngestCount = inmate[i].pnum;
}
if(inmate[i].sentence > maxSentence)
{
maxSentence = inmate[i].sentence;
sentenceCount = inmate[i].cellNum;
}
}
for(int i=0;i<inmate.length;i++)
{
System.out.println(" ");
System.out.println("#" + inmate[i].getNumber());
System.out.println("Name: " + inmate[i].getSurname() + ", " + inmate[i].getForename());
System.out.println("Age: " + inmate[i].getAge());
System.out.println("Sentence: " + inmate[i].getSentence() + " years");
System.out.println(" ");
}
//print other details
System.out.println("The eldest inmate is " + maxAge + " years old.");
System.out.println("#" + youngestCount + " is the youngest inmate.");
System.out.println("Cell #" + sentenceCount + " is serving the longest sentence.");
int yearsCount = 0;
System.out.println(" ");
System.out.println(" ");
for(int j=0;j<inmate.length;j++)
{
sentenceCount = inmate[j].sentence / 2;
for(int i=0;i<100;i++)
{
inmate[j].age += 1;
inmate[j].sentence -= 1;
if(inmate[j].age == 70 || inmate[j].sentence == sentenceCount)
{
i = 100;
System.out.println("#" + inmate[j].pnum + " will be released after " + yearsCount + " years.");
}
else
{
yearsCount += 1;
}
}
}
System.out.println(" ");
System.out.println(" ");
System.out.println("!PROGRAM END!");
System.exit(0);
}
}
[/b]
Separate class:
[b]
class prisoner
{
String forename, surname;
int age, sentence, pnum=47, cellNum;
public void setName()
{
forename=getit.forename();
surname=getit.surname();
}
public String getForename()
{
return forename;
}
public String getSurname()
{
return surname;
}
public void setAge()
{
age=getit.age();
}
public int getAge()
{
return age;
}
public void setSentence()
{
sentence=getit.sentence();
}
public int getSentence()
{
return sentence;
}
public void setNumber()
{
double num;
num=Math.random();
num=num * 100;
num = Math.round(num);
pnum = (int)num;
}
public int getNumber()
{
return pnum;
}
public void setCellnum(int i)
{
cellNum=i + 1;
}
}