I have these two methods. I understand the "getTotalSalary" one but don't really get the way in which "getAverageSalary" is written. I don't understand why the question mark and colon is used as well as the "(size() != 0)" and 0 at the end.
This is the coding:
public double getTotalSalary() {
double total = 0;
for (Employee e : empReg) {
total = total + e.getSalary();
}
return total;
}
public double getAverageSalary() {
return (size() != 0) ? this.getTotalSalary() / this.size() : 0;
}
empReg is the name of the ArrayList. Employee is a class which consists of "name" and "salary". getSalary is obviously a method returning the salary.