fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. public class TaskEmployee {
  8. public static void main(String[] args) {
  9. DataBase dataBase = new DataBase();
  10. for (Employee em : dataBase.findByString("ge")) {
  11. System.out.println("FindByString \n" + em.toString());
  12. }
  13. dataBase.setDateNow("2015 1");
  14. for (Employee em : dataBase.findByYears(2)) {
  15. System.out.println("findByYears\n" + em.toString());
  16. }
  17. }
  18. }
  19.  
  20. class Employee {
  21. private String lastName;
  22. private String firstName;
  23. private String midName;
  24. private String address;
  25. private String date;
  26.  
  27. public Employee(String lastName, String firstName, String midName, String address, String date) {
  28. this.lastName = lastName;
  29. this.firstName = firstName;
  30. this.midName = midName;
  31. this.address = address;
  32. this.date = date;
  33. }
  34.  
  35. public Employee(String lastName, String firstName, String address, String date) {
  36. this.lastName = lastName;
  37. this.firstName = firstName;
  38. this.address = address;
  39. this.date = date;
  40. }
  41.  
  42. public String getLastName() {
  43. return lastName;
  44. }
  45.  
  46. public void setLastName(String lastName) {
  47. this.lastName = lastName;
  48. }
  49.  
  50. public String getFirstName() {
  51. return firstName;
  52. }
  53.  
  54. public void setFirstName(String firstName) {
  55. this.firstName = firstName;
  56. }
  57.  
  58. public String getMidName() {
  59. return midName;
  60. }
  61.  
  62. public void setMidName(String midName) {
  63. this.midName = midName;
  64. }
  65.  
  66. public String getAddress() {
  67. return address;
  68. }
  69.  
  70. public void setAddress(String address) {
  71. this.address = address;
  72. }
  73.  
  74. public String getDate() {
  75. return date;
  76. }
  77.  
  78. public void setDate(String date) {
  79. this.date = date;
  80. }
  81.  
  82. public int getYear(String now) {
  83. int year = Integer.parseInt(now.split(" ")[0]);
  84. int month = Integer.parseInt(now.split(" ")[1]);
  85. String date = getDate();
  86. int y = Integer.parseInt(date.split(" ")[0]);
  87. int m = Integer.parseInt(date.split(" ")[1]);
  88. y = year - y;
  89. if (month < m) {
  90. y--;
  91. }
  92. return y;
  93. }
  94.  
  95. @Override
  96. public String toString() {
  97. return "Employee : " +
  98. "lastName='" + lastName + '\'' +
  99. ", firstName='" + firstName + '\'' +
  100. ", midName='" + midName + '\'' +
  101. ", address='" + address + '\'' +
  102. ", date='" + date + '\'';
  103. }
  104. }
  105.  
  106. class DataBase {
  107.  
  108. private List<Employee> employeeList;
  109. private String dateNow;
  110.  
  111. public DataBase() {
  112. this.employeeList = new ArrayList<Employee>();
  113. employeeList.add(new Employee("Vihrev", "Petr", "Petrovich", "Ivanovo", "2010 5"));
  114. employeeList.add(new Employee("Petrov", "Vasiliy", "Ivanovich", "Kazan", "2011 3"));
  115. employeeList.add(new Employee("Gareev", "Evgeniy", "Ufa", "2015 5"));
  116. employeeList.add(new Employee("Plotnikov", "Georgiy", "Omsk", "2012 1"));
  117. employeeList.add(new Employee("Grishakov", "Roman", "Mihaylovich", "Moscow", "2014 8"));
  118. }
  119.  
  120. public String getDateNow() {
  121. return dateNow;
  122. }
  123.  
  124. public void setDateNow(String dateNow) {
  125. this.dateNow = dateNow;
  126. }
  127.  
  128. public List<Employee> getEmployeeList() {
  129. return employeeList;
  130. }
  131.  
  132. public List<Employee> findByYears(int year) {
  133. List<Employee> res = new ArrayList<>();
  134. for (Employee emp : getEmployeeList()) {
  135. if (emp.getYear(getDateNow()) >= year) {
  136. res.add(emp);
  137. }
  138. }
  139. return res;
  140. }
  141.  
  142. public List<Employee> findByString(String ex) {
  143. List<Employee> res = new ArrayList<>();
  144. String reg = ex.toLowerCase();
  145. for (Employee emp : getEmployeeList()) {
  146. String sum = (emp.getFirstName() + " " + emp.getLastName() + " " + emp.getMidName()).toLowerCase();
  147. if (sum.contains(reg)) {
  148. res.add(emp);
  149. }
  150. }
  151. return res;
  152. }
  153. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:7: error: class TaskEmployee is public, should be declared in a file named TaskEmployee.java
public class TaskEmployee {
       ^
1 error
stdout
Standard output is empty