Ucze się z Core Java. Mam problem z dodaniem metody, która liczyłaby średnią arytmetyczną zarobków. Nie potrafię tego zrobić tak, aby metoda ta była w klasie Employee(moglbym to obliczyc w EmployeeTest, ale chyba to byłoby niezbyt poprawne).
public class EmployeeTest {
public static void main(String[] args) {
double percent = 8;
Employee[] staff = new Employee[3];
staff[0] = new Employee("Paul Kowalsky", 5000, 2010, 10, 23);
staff[1] = new Employee("John Travolta", 80000, 2006, 4, 15);
staff[2] = new Employee("Clint Eastwood", 15000, 2004, 12, 7);
for(Employee e : staff) {
System.out.println(e.getName() + ", " + e.getSalary() + "$, since " + e.getHireDay());
}
for(Employee e : staff) {
e.raiseSalary(percent);
}
System.out.println("\nAfter a " + percent + "% raise: ");
for(Employee e : staff) {
System.out.println(e.getName() + ", " + e.getSalary());
}
}
}
class Employee {
private String name;
private int salary;
private Date hireDay;
public Employee(String n, int s, int year, int month, int day){
name = n;
salary = s;
GregorianCalendar calendar = new GregorianCalendar(year, month-1, day);
hireDay = calendar.getTime();
}
public String getName() {
return name;
}
public int getSalary() {
return salary;
}
public Date getHireDay() {
return hireDay;
}
public void raiseSalary(double byPercent) {
double raise = byPercent * salary / 100;
salary += raise;
}
}
Dopiero zaczynam poznawać obiektowość, dlatego też proszę o wyrozumiałość i pomoc