-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployeeDetails.java
81 lines (64 loc) · 2.03 KB
/
EmployeeDetails.java
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
import java.util.*;
class Employee{
String name;
int age;
String phNo;
String ad;
int sal;
void print_Salary(){
System.out.print("Salary: " + sal);
}
}
class Officer extends Employee{
String spec;
}
class Manager extends Employee{
String dep;
}
class EmployeeDetails{
static void Input(Employee tempObj){
Scanner sc = new Scanner(System.in);
System.out.print("Enter The Name: ");
tempObj.name = sc.nextLine();
System.out.print("Enter The Age: ");
tempObj.age = sc.nextInt();
sc.nextLine();
System.out.print("Enter The Phone Number: ");
tempObj.phNo = sc.nextLine();
System.out.print("Enter The Address Of The Employee: ");
tempObj.ad = sc.nextLine();
System.out.print("Enter The Salary Of The Employee: ");
tempObj.sal = sc.nextInt();
sc.nextLine();
if (tempObj instanceof Officer) {
System.out.print("Enter The Specialization Of The Officer: ");
((Officer) tempObj).spec = sc.nextLine();
} else if (tempObj instanceof Manager) {
System.out.print("Enter The Department Of The Manager: ");
((Manager) tempObj).dep = sc.nextLine();
}
}
static void display(Employee tempObj, String emp){
System.out.println("\n\n" + emp + " Name: " + tempObj.name);
System.out.println(emp + " Age: " + tempObj.age);
System.out.println(emp + " Phone Number: " + tempObj.phNo);
System.out.println(emp + " Address: " + tempObj.ad);
if (tempObj instanceof Officer) {
System.out.println(emp + " Specialization: " + ((Officer) tempObj).spec);
} else if (tempObj instanceof Manager) {
System.out.println(emp + " Department: " + ((Manager) tempObj).dep);
}
}
public static void main(String a[]){
Officer ofcObj = new Officer();
Manager mngObj = new Manager();
System.out.println("\n\t\t\t\t\t================= Details Of Officer =================");
Input(ofcObj);
System.out.println("\n\t\t\t\t\t================= Details Of Manager =================");
Input(mngObj);
display(ofcObj, "Officer");
ofcObj.print_Salary();
display(mngObj, "Manager");
mngObj.print_Salary();
}
}