agony_aunt No wonder she threw you out! Your code is politically incorrect! Let me tell you why. Here's a piece of your code:
class Employee
{
Gender gender;
String name;
public Employee(String name, Gender gender)
{
this.name = name;
this.gender = gender;
}
...
}
...
Employee employee = new Employee("Ramya", Gender.Female);
Do you see what you did wrong there? You objectified women! You are such a sexist pig! Women should never be represented by objects. You should do this intead:
int calculateSalary(String name)
{
if(isMale(name))
{
Employee man = getEmployeeByName(name);
return man.getSalary();
}
else
{
//be careful not to create an object, not even a structure.
return getSalaryForFemalePerson(name);
}
}
The second mistake you did was here:
class Employee
{
...
int getAge()
{
return age;
}
...
}
You can't ask a woman her age! Thats rude, and in some countries, it's illegal! This is what you should do:
int getAge(String name)
{
if(isMale(name))
{
Employee man = getEmployeeByName(name);
return man.getAge();
}
else
{
throw new SexistException("Male Chauvinist Pig!");
}
}
Your comparison function is also totally wrong. What it should be doing is:
int compareEmployees(String emp1, String emp2)
{
if(isMale(emp1) && isFemale(emp2))
return -1;//men are inferior to women.
if(isFemale(emp1) && isMale(emp2))
return +1;//women are superior to men.
if(isFemale(emp1) && isFemale(emp2))
//woman with more jewelry wins.
return getJewelry(emp1) - getJewelry(emp2);
return 0;//all men are equally stupid.
}
Even though it is a payroll application, you always need to implement these functions:
boolean isFat(String name)
{
if(isMale(name))
{
Employee man = getEmployeeByName(name);
return man.getWeight() > AVERAGE_WEIGHT;
}
else
{
return false;
}
}