-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEmployee.java
More file actions
168 lines (138 loc) · 3.34 KB
/
Employee.java
File metadata and controls
168 lines (138 loc) · 3.34 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// SRP
// Encapsulation = Data + Methods in a Single Unit
// and this is called Class
// Data Hiding = Making your Data as Private
// Good Encapsulation = Data Hiding + public methods
public class Employee {
private int id; // Member Variable or Instance Variables
private String name;
private String address;
private double salary;
private String phone;
private String companyName;
private String gender;
private String email;
private String dept;
private String manager;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public int getId() {
return id;
}
public String getGender() {
return gender;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public String getManager() {
return manager;
}
public void setManager(String manager) {
this.manager = manager;
}
/*
* Constructor -> Constructor is same like a method
* Class Name and Constructor Name is Same
* It is Called when you create a New Object
* And It is used to Initalize the Instance Variables
* It does not return any Value
* Every Class By Default has Default Constructor
* And If you create Any Other Constructor then Default
* Constructor is Gone (If you not created the Default)
*/
Employee(){
//this(102,"Ram", "Mumbai", 9090, "3422");
companyName="TCS";
}
Employee(int i , String name , double salary ){
// Assign Local Variable into Instance Variable
//Employee();
this(); // Now it is calling Default Constructor of the Same Class
if(i>0 && salary>0){
//id = i*companyName.length();
id = i;
this.name = name;
//this.address = address;
this.salary = salary;
//this.phone = phone;
}
else
{
System.out.println("Invalid Data");
}
}
private double calculateDA(){
return salary * 0.10;
}
private double calculateTA(){
return salary * 0.20;
}
private double calculatePF(){
return salary * 0.20;
}
private double calculateHRA(){
return salary * 0.50;
}
public double calculateSalary(){
return salary + calculateHRA() + calculateDA() +calculateTA()+ calculatePF();
}
/*public void takeInput(int i , String name , String address , double salary , String phone){
// Assign Local Variable into Instance Variable
if(i>0 && salary>0){
id = i;
this.name = name;
this.address = address;
this.salary = salary;
this.phone = phone;
}
else
{
System.out.println("Invalid Data");
}
}*/
// this -> It a Predefine Keyword and it store the current
// object reference
/*public void print(){
System.out.println("Id: "+id+" Name: "+name
+" Salary: "+this.salary+" Phone: "+this.phone
+" Address: "+this.address+" Company Name "+this.companyName);
}*/
}