Проблема с задачей на поиск в массиве/arraylist

Есть задача - Напечатать фамилию, имя, отчество и адрес сотрудников...(Златопольский 13.12)

import java.util.ArrayList;
import java.time.LocalDate;
import java.util.Scanner;

public class workexp {
    public static void main(String[] args) {
        Database DB = new Database();
        ArrayList<Employee> employees = new ArrayList<>();
        employees.add(new Employee("Путин", "Владимир", "Владимирович", 2000, 12));
        employees.add(new Employee("Медведев", "Дмитрий", "Анатольевич", 2008, 5));
        employees.add(new Employee("Хренова", "Гадя", "Петрович", 2017, 3));
        employees.add(new Employee("Кшыштопоповжецкая", "Изольда", 2017, 5));
    }
}


class Employee {
    String surname;
    String name;
    String patronymic;
    int year;
    int month;

    public Employee(String surname, String name, int year, int month) {
        this.surname = surname;
        this.name = name;
        this.patronymic = "";
        this.year = year;
        this.month = month;
    }

    public Employee(String surname, String name, String patronymic, int year, int month) {
        this.surname = surname;
        this.name = name;
        this.patronymic = patronymic;
        this.year = year;
        this.month = month;
    }

    public String getName() {
        return name;
    }

    public int getYear() {
        return year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth() {
        this.month = month;
    }

    public String getFullName() {
        return surname + name + patronymic;
    }


    int getWorkinExpirienceOnDate() {
        if (LocalDate.now().getYear() - year > 3) {
            return System.out.println(Employee.getFullName());
        } else if (LocalDate.now().getYear() - year == 3) {
            if (((LocalDate.now().getMonth()) - month) >= 0) {
                return Employee.getFullName();
            }
        } else break;
        break;
    }

}

class Database(Employee[]employees) {
Employee[] findEmployees(String FullNameSubstring) {
// if Employee == getFullName return Employee.experience //видимо возврат опыта работы по фамилии
}

Employee[] findEmployees(int workingYears) {
//if Employee == experience return employee.getfullname  //видимо возврат фамилии по опыту работу
}

}


Ответы (1 шт):

Автор решения: Дмитрий

Очень правильный вопрос, думаю ответ будет вам очень полезен.

import java.util.ArrayList;
import java.time.LocalDate;
import java.time.Period;

public class MoreThanthree {
    public static void main(String[] Args) {

        ArrayList<Employee> staff = new ArrayList<>();
        staff.add(new Employee("Путин", "Владимир", "Владимирович", "Ново-Огарёво", LocalDate.of(2000, 12, 1)));
        staff.add(new Employee("Медведев", "Дмитрий", "Анатольевич", "рядом с Путиным, иначе всесте с Шпаком", LocalDate.of(2008, 5, 1)));
        staff.add(new Employee("Семён", "Семёнович", "Шпак", "Мухосранск", LocalDate.of(2008, 8, 1)));
        staff.add(new Employee("Антон", "Городецкий", "Батькович", "рядом с Мухосранском", LocalDate.of(2010, 1, 1)));
        staff.add(new Employee("Гадя", "Петрович", "Хренова", "Москва", LocalDate.of(2017, 3, 1)));
        staff.add(new Employee("Оксана", "Оксановна", "Петрович", "деревня Гадюкино", LocalDate.of(2017, 5, 1)));

        System.out.println("СПИСОК ВСЕХ РАБОТНИКОВ");
        staff.forEach(System.out::println);

        System.out.println("*************************************************");

        final int experienceInYear = 3;
        System.out.println("СПИСОК РАБОТНИКОВ, СО СТАЖЕМ РАБОТЫ ОТ "+experienceInYear+" ЛЕТ");        

        staff.stream()
                .filter(employee->employee.experienceInYear()>=experienceInYear)
                .forEach(System.out::println);

    }

}

class Employee {

    private final String surname;
    private final String name;
    private final String patronomic;
    private final String city;
    private final LocalDate experience;

    public Employee(String surname, String name, String patronomic, 
            String city, LocalDate experience){
        this.surname = surname;
        this.name = name;
        this.patronomic = patronomic;
        this.city = city;
        this.experience = experience;
    }

    public String getCity(){
        return city;
    }

    public int experienceInYear () {
        return Period.between(experience, LocalDate.now()).getYears();        
    }

    @Override
    public String toString() {
        return surname + " " + name + " " + patronomic + ", стаж в годах : " + experienceInYear ();
    }

}
→ Ссылка