asked on
package TaskCh;
import java.util.ArrayList;
import java.util.Calendar;
/**
*/
//********** ************************************************************
class SearchEngine {
public void searchRequest(ArrayList<Employee> db, int numberOfyears) {
for (Employee item : db) {
if (item.getYearsOfWork() >= numberOfyears) {
item.getRequestedInformation();
}
}
}
}
//********** ************************************************************
//********** ************************************************************
class Employee { // Class Employee // start
private String firstName;
private String middleName;
private String familyName;
private String address;
private int yearOfstart;
private int monthOfstart;
// The constructor of the class // starts
Employee (String firstName,
String middleName,
String familyName,
String address,
int yearOfstart,
int monthOfstart) {
this.familyName = familyName;
this.firstName = firstName;
this.middleName = middleName;
this.address = address;
this.yearOfstart = yearOfstart;
this.monthOfstart = monthOfstart;
}
// Second constructor ( in case of if middle name's absents )
Employee (
String firstName,
String familyName,
// missing middle name of an employee
String address,
int yearOfstart,
int monthOfstart)
{
this.familyName = familyName;
this.firstName = firstName;
this.address = address;
this.yearOfstart = yearOfstart;
this.monthOfstart = monthOfstart;
}
// The constructor of the class // ends
// Implementation of getters methods // Start
public String getFirstName() {
return firstName;
}
public String getMiddleName() {
if (middleName == null) {
return "";
} else {
return middleName;
}
}
public String getFamilyName() {
return familyName;
}
public String getAddress() {
return address;
}
public int getYearOfStart() {
return yearOfstart;
}
public int getMonthOfStart() {
return monthOfstart;
}
// Implementation of getters methods // ends
// Business logic // Start
// method for calculation of beginning of a career in a company
public int getYearsOfWork () {
Calendar c = Calendar.getInstance();
if ( (monthOfstart - 1) <= c.get(Calendar.MONTH) ) {
return c.get(Calendar.YEAR) - yearOfstart;
} else {
return c.get(Calendar.YEAR) - yearOfstart - 1;
}
}
public void getRequestedInformation() {
System.out.printf ( "\nFull name : %s " ,this.getFirstName()) ;
System.out.printf ( "%s " ,this.getMiddleName()) ;
System.out.printf ( "%s " ,this.getFamilyName()) ;
System.out.printf ( "\nAddress : %s" ,this.getAddress()) ;
System.out.printf ( "\nstart date ( yyyy/mm ) : %s" ,this.getYearOfStart()) ;
System.out.printf ( " / %s" ,this.getMonthOfStart()) ;
System.out.println("\n\n *** next employee");
}
// Business logic // ends
} // Class Employers // ends
// ********** ************************************************************
// enum EmpoyeeDataBase {
//
// ArrayList<Employee> empoyeeDataBase = new ArrayList<>();
//
// empoyeeDataBase.add(new Employee("Jack", "Dorsy","USA, CA, San-Francisco", 2008, 11));
// empoyeeDataBase.add(new Employee("Barack", "Obama","USA, DC, Washington", 2016, 12));
// empoyeeDataBase.add(new Employee("Larry ", "Page","USA, CA, San-Francisco", 2015, 10));
// empoyeeDataBase.add(new Employee("Sergey ","Brin","USA, CA, San-Francisco", 2014, 10));
// empoyeeDataBase.add(new Employee("Elon", "Musk","USA, CA, Los_Angeles", 2013, 8)); // Works almost 3 years
// empoyeeDataBase.add(new Employee("Pavel","M.", "Durov","Russia, Saint-Petersburg", 2012, 12));
// empoyeeDataBase.add(new Employee("Dmitriy", "V.", "Medvedev","Russia", 2015, 10));
//
// }
public class TaskCh {
public static void main(String[] args) {
// ArrayList of Employee type
ArrayList<Employee> empoyeeDataBase = new ArrayList<>();
// Fill ArrayList
empoyeeDataBase.add(new Employee("Jack", "Dorsy","USA, CA, San-Francisco", 2008, 11));
empoyeeDataBase.add(new Employee("Barack", "Obama","USA, DC, Washington", 2016, 12));
empoyeeDataBase.add(new Employee("Larry ", "Page","USA, CA, San-Francisco", 2015, 10));
empoyeeDataBase.add(new Employee("Sergey ","Brin","USA, CA, San-Francisco", 2014, 10));
empoyeeDataBase.add(new Employee("Elon", "Musk","USA, CA, Los_Angeles", 2013, 8)); // Works almost 3 years
empoyeeDataBase.add(new Employee("Pavel","M.", "Durov","Ukraine, Kiev", 2012, 12));
empoyeeDataBase.add(new Employee("Dmitriy", "V.", "Medvedev","Ukraine , Lviv", 2015, 10));
// For each in "a" (print -> not less than 3 years of work)
System.out.println("Information about Employees who works more than 3 years : ");
SearchEngine yearRequest = new SearchEngine();
yearRequest.searchRequest(empoyeeDataBase, 3);
}
}
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.
TRUSTED BY