package com litvynchuk lab1 util import com litvynchuk lab1 model Work

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.litvynchuk.lab1.util;
import com.litvynchuk.lab1.model.Worker;
import oracle.jrockit.jfr.events.Bits;
import java.util.Random;
public class WorkerBuilder {
private String surname;
private String name;
private int employmentYear;
private int yearOfBirth;
private String baseWorkPlace;
private static String[] arNames = {"name1", "name2", "name3"};
private static String[] arSurnames = {"surname1", "surname2", "surname3"};
private static int[] arEmploymentYears = {2010, 2011, 2012, 2013, 2014};
private static int[] arYearsOfBirth = {1975, 1985, 1979, 1989, 1995};
private static String[] arWorkplaces = {"Apple", "Microsoft", "IBM", "Sumsung", "Google"};
public WorkerBuilder setSurname(String surname) {
this.surname = surname;
return this;
}
public WorkerBuilder setName(String name) {
this.name = name;
return this;
}
public WorkerBuilder setEmploymentYear(int employmentYear) {
this.employmentYear = employmentYear;
return this;
}
public WorkerBuilder setYearOfBirth(int yearOfBirth) {
this.yearOfBirth = yearOfBirth;
return this;
}
public WorkerBuilder setBaseWorkPlace(String baseWorkPlace) {
this.baseWorkPlace = baseWorkPlace;
return this;
}
public Worker build() {
return new Worker(surname, employmentYear, name, yearOfBirth, baseWorkPlace);
}
public Worker[] generateWorkers(int numberOfWorkersToGenerate){
Worker workers[] = new Worker[numberOfWorkersToGenerate];
Random rand = new Random();
int i = 0;
for(Worker worker : workers){
workers[i] = new WorkerBuilder()
.setName(arNames[rand.nextInt(arNames.length)])
.setSurname(arSurnames[rand.nextInt(arSurnames.length)])
.setEmploymentYear(arEmploymentYears[rand.nextInt(arEmploymentYears.length)])
.setBaseWorkPlace(arWorkplaces[rand.nextInt(arWorkplaces.length)])
.setYearOfBirth(arYearsOfBirth[rand.nextInt(arYearsOfBirth.length)])
.build();
i++;
}
return workers;
}
}