class Person
{
private String name;
private String profession;
}
profession has values:
- engineer
- Doctor<
Add enum to your variables:
class Person {
private String name;
private String profession;
private enum enumProffesion
{
Doctor, Teacher, student;
}
}
After that could add function to the Person class which would give you value of the profession:
public int professionValue()
{
enumProffesion enumValue= enumProffesion.valueOf(proffesion);
switch (enumValue) {
case Doctor: return 1; break;
case Teacher: return 2; break;
case student: return 3; break;
default: return null;
}
}
After that you just implement logic that will sort all Persons. For that you can help your self with this answer: sorting integers in order lowest to highest java