-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployeeStaus.java
More file actions
57 lines (56 loc) · 1.71 KB
/
EmployeeStaus.java
File metadata and controls
57 lines (56 loc) · 1.71 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
package com.EmployeeStatus;
import java.util.Scanner;
public class EmployeeStaus{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
String name=sc.next();
double salary=Double.parseDouble(sc.next());
double bonus=sc.nextDouble();
Employee e1=new Employee(name,salary);
SecureEmployee s1=new SecureEmployee(name,salary,bonus);
System.out.println(e1.displayDetails());
System.out.println(s1.displayDetails());
System.out.println(s1.performanceStatus());
sc.close();
}
}
class Employee{
String name;
double salary;
Employee(String name,double salary){
this.name=name;
this.salary=salary;
}
public String displayDetails(){
return "Without Encapsulation:\nName : "+name+"\nSalary : "+salary+"\n(Fields can be modified directly!)";
}
}
class SecureEmployee extends Employee{
private double bonus;
SecureEmployee(String name,double salary,double bonus){
super(name,salary);
setBonus(bonus);
}
public void setBonus(double bonus){
this.bonus=bonus;
}
public double getBonus(){
return bonus;
}
@Override
public String displayDetails(){
return "\nWith Encapsulation (Overridden):\nName : "+name+"\nSalary : "+salary+"\nBonus : "+bonus;
}
public String performanceStatus(){
System.out.println("\nPerformance Status:");
if(salary+bonus>=100000){
return "Excellent Performer";
}
if(salary+bonus>=50000){
return "Good Performer";
}
else{
return "Needs Improvement";
}
}
}