-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployees.java
More file actions
56 lines (49 loc) · 1.48 KB
/
Copy pathEmployees.java
File metadata and controls
56 lines (49 loc) · 1.48 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
/* You are building an employee management system and need to create an Employee class. The Employee class should have private instance
variables for the employee name, employee ID, and salary. Implement getter and setter methods for the name and ID, but ensure that the salary
can only be updated through a specific method that increases or decreases the amount while preventing negative values.*/
// Manjil Basnet
public class Employees {
private String name;
private String ID;
private double salary;
public Employees(double salary){
this.salary = salary;
}
// setter
public void setName(String name) {
this.name = name;
}
public void setID(String ID) {
this.ID = ID;
}
// getter
public String getName() {
return name;
}
public String getID() {
return ID;
}
public double getSalary() {
return salary;
}
public void updateSalary(double amount) {
if (this.salary + amount >= 0) {
this.salary += amount;
}
}
public void employeeinfo(){
System.out.println("Name: " + getName());
System.out.println("ID: " + getID());
System.out.println("Salary: " + getSalary());
}
}
class EmployeesDriver{
public static void main(String[] args) {
Employees e1 = new Employees(20000);
e1.setName("Shyam");
e1.setID("E101");
e1.updateSalary(5000);
e1.getSalary();
e1.employeeinfo();
}
}