-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
60 lines (52 loc) · 1.54 KB
/
Copy pathEmployee.java
File metadata and controls
60 lines (52 loc) · 1.54 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
// Write a Java program to create a class called "Employee" with a name, job title, and salary attributes, and methods to calculate and update salary.
// Manjil Basnet
public class Employee {
private String name;
private String jobTitle;
private double salary;
// constructor
public Employee(String name, String jobTitle, double salary){
this.name = name;
this.jobTitle = jobTitle;
this.salary = salary;
}
// setter
public void setName(String name){
this.name = name;
}
public void setJobTitle(String jobTitle){
this.jobTitle = jobTitle;
}
public void setSalary(double salary){
this.salary = salary;
}
// getter
public String getName(){
return name;
}
public String getJobTitle(){
return jobTitle;
}
public double getSalary(){
return salary;
}
public void updateSalary(double percentage) {
salary += salary * (percentage / 100);
}
// method to display info
public void displayinfo(){
System.out.println("Name: " + getName());
System.out.println("Job Title: " + getJobTitle());
System.out.println("Salary: " + getSalary());
}
}
class EmployeeDriver{
public static void main(String[] args) {
Employee e = new Employee("Ram", "Software Engineer", 50000);
System.out.println("Before salary update");
e.displayinfo();
e.updateSalary(10);
System.out.println("\nAfter Salary Increase:");
e.displayinfo();
}
}