-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
64 lines (53 loc) · 2.02 KB
/
Copy pathEmployee.java
File metadata and controls
64 lines (53 loc) · 2.02 KB
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
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
public class Employee {
private GregorianCalendar birthDate= new GregorianCalendar();
private String name;
private String lastName;
private String post;
public String email;
public String phone;
public int salary;
Employee(String name, String lastName, String dateOfBirth, String post, int salary, String email, String phone) throws ParseException {
SimpleDateFormat sdf=new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
this.name=name;
this.lastName=lastName;
this.post=post;
this.salary=salary;
this.email=email;
this.phone=phone;
this.birthDate.setTime(sdf.parse(dateOfBirth));
}
int GetAge(){
int age=-1;
if (this.birthDate.get(Calendar.DAY_OF_YEAR)<=GregorianCalendar.getInstance().get(Calendar.DAY_OF_YEAR)) age+=1;
age+=GregorianCalendar.getInstance().get(Calendar.YEAR)-this.birthDate.get(Calendar.YEAR);
return age;
}
void PrintData(){
SimpleDateFormat sdf=new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
String toPrint;
String secondString;
String thirdString;
toPrint="ФИО: "+this.lastName+" "+this.name;
toPrint=MakeStraight(toPrint);
toPrint+="Дата рождения: "+ sdf.format(this.birthDate.getTime());
secondString="Должность: "+post;
secondString=MakeStraight(secondString);
secondString+="Оклад: " + salary+ "\nКонтакты:";
thirdString="Телфон: "+phone;
thirdString=MakeStraight(thirdString);
thirdString+="E-mail: " + email;
System.out.println(toPrint+"\n"+secondString+"\n"+thirdString+"\n");
}
String MakeStraight(String input){
int doStraight=40-input.length();
for (int i=0; i<doStraight;i++){
input+=" ";
}
return input;
}
}