Created class:
public class Employee { private String fullName; private String position; private String email; private int phoneNumber; private int salary; private byte age; //геттеры и сеттеры public String getFullName() { return fullName; } public void setFullName(String fullName) { this.fullName = fullName; } public String getPosition() { return position; } public void setPosition(String position) { this.position = position; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public int getPhoneNumber() { return phoneNumber; } public void setPhoneNumber(int phoneNumber) { this.phoneNumber = phoneNumber; } public int getSalary() { return salary; } public void setSalary(int salary) { this.salary = salary; } public byte getAge() { return age; } public void setAge(byte age) { this.age = age; } //параметризированный конструктор public Employee(String fullName, String position, String email, int phoneNumber, int salary, byte age) { this.fullName = fullName; this.position = position; this.email = email; this.phoneNumber = phoneNumber; this.salary = salary; this.age = age; } In another class, an array is created:
public class EmployeeDemo { public static void main(String[] args) { Employee [] mas = new Employee[5]; mas[0] = new Employee("KozlovAA", "developer", "kozlovaa@mail.ru", 123456, 10000, (byte) 30); mas[1] = new Employee("IvanovAA", "engineer", "IvanovAA@mail.ru", 321654, 15000, (byte) 35); mas[2] = new Employee("PetrovEE", "manager", "PetrovEE@mail.ru", 234651, 8000, (byte) 40); mas[3] = new Employee("SidorovAA", "seller", "SidorovAA@mail.ru", 654321, 7000, (byte) 45); mas[4] = new Employee("AbramovichRO", "businessman", "AbramovichRO@mail.ru", 112233, 100000, (byte) 50); } } It is necessary in the EmployeeDemo class to create a method that, using a cycle, will output to the console all the objects of this array, whose field is age> 40; This method does not work - please tell me what am I doing wrong?
public void sortOfAge() { for (int i = 0; i < mas.length; i++) { if (this.getAge() > 40) { System.out.println("ФИО: " + fullName); System.out.println("должность: " + position); System.out.println("email: " + email); System.out.println("телефон: " + phoneNumber); System.out.println("зарплата: " + salary); System.out.println("возраст: " + age); } }