-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee_Manager.java
More file actions
118 lines (117 loc) · 3.41 KB
/
Copy pathEmployee_Manager.java
File metadata and controls
118 lines (117 loc) · 3.41 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
import java.util.Scanner;
class Employee
{
protected int emp_id;
protected String name;
protected String department;
protected double salary;
protected String designation;
public Employee(int emp_id,String name,String department,double salary,String designation)
{
this.emp_id=emp_id;
this.name=name;
this.department=department;
this.salary=salary;
this.designation=designation;
}
public int getid()
{
return emp_id;
}
public String getname()
{
return name;
}
public String getdepartment()
{
return department;
}
public double getsalary()
{
return salary;
}
public String getdesignation()
{
return designation;
}
public boolean equals(Employee e1)
{
return(e1.designation.equals(this.getdesignation()));
}
public void addBonus()
{
salary+=200;
}
public void display()
{
System.out.println("ID: "+getid());
System.out.println("Name: "+getname());
System.out.println("salary: "+getsalary());
System.out.println("designation: "+getdesignation());
System.out.println("Departemt: "+getdepartment());
}
}
class Manager extends Employee
{
public Manager(int id,String name,String department,double salary,String designation)
{
super(id,name,department,salary,designation);
}
public void addBonus()
{
salary+=300;
}
}
class clerk extends Employee
{
public clerk(int id,String name,String department,double salary,String designation)
{
super(id,name,department,salary,designation);
}
public void addBonus()
{
salary+=100;
}
}
public class Employee_Manager
{
public static void main(String[] args)
{
int id;
String name,department,designation;
double salary;
Scanner s1=new Scanner(System.in);
Employee [] e1=new Employee[3];
for(int i=0;i<3;i++)
{
System.out.println("Enter employee details");
System.out.println("ID: ");
id=s1.nextInt();
System.out.println("Name: ");
name=s1.next();
System.out.println("Department: ");
department=s1.next();
System.out.println("Salary: ");
salary=s1.nextDouble();
System.out.println("Designation: ");
designation=s1.next();
designation=designation.toLowerCase();
if (designation.equals("manager"))
{
e1[i]=new Manager(id,name,department,salary,designation);
}
if (designation.equals("clerk"))
{
e1[i]=new clerk(id,name,department,salary,designation);
}
}
System.out.println("Does employee1 and employee2 are equal: "+e1[0].equals(e1[1]));
System.out.println("Does employee1 and employee3 are equal: "+e1[0].equals(e1[2]));
e1[0].addBonus();
e1[1].addBonus();
e1[2].addBonus();
System.out.println(e1[0].getname()+"salary after adding bonus: "+e1[0].getsalary());
System.out.println(e1[1].getname()+"salary after adding bonus: "+e1[1].getsalary());
System.out.println(e1[2].getname()+"salary after adding bonus: "+e1[2].getsalary());
}
}