-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram68.java
More file actions
84 lines (60 loc) · 2.09 KB
/
Copy pathprogram68.java
File metadata and controls
84 lines (60 loc) · 2.09 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
/*
Experiment No. 2: Employee Salary Calculator
Aim
To study the concepts of Method Overloading, Constructor Overloading, Static Variable,
and Static Method in Java.
Problem Statement
Create an Employee class with the following data members:
• Employee ID
• Employee Name
• Basic Salary
Implement the following:
1. Use constructor overloading to initialize employee details.
2. Use method overloading to calculate salary:
o Salary without bonus.
o Salary with bonus.
3. Use a static variable to count the total number of employees created.
4. Use a static method to display the total number of employees.
*/
class Employee{
int empID;
String empName;
double basicSalary;
static int employeeCount = 0;
Employee(int empId, String empName, double basicSalary){
this.empID = empId;
this.empName = empName;
this.basicSalary = basicSalary;
employeeCount++;
}
void CalculateSalary(){
System.out.println("Salary without Bonus : " + basicSalary);
}
void CalculateSalary(double bonus){
double totalSalary = basicSalary + bonus;
System.out.println("Salary with Bonus : " +totalSalary);
}
void displayEmployee(){
System.out.println("Employee Name : " + empName);
System.out.println("Employee ID : " + empID);
System.out.println("Employee Salary : " + basicSalary);
}
static void displayEmployeeCount(){
System.out.println("Total Employee Count : " + employeeCount);
}
}
public class program68{
public static void main(String[] args) {
Employee E1 = new Employee(066, "Shalabh", 2000000000);
Employee E2 = new Employee(067, "Zuck", 50000000);
System.out.println("--------------Employee 1-------------");
E1.displayEmployee();
E1.CalculateSalary();
E1.CalculateSalary(13000);
System.out.println("--------------Employee 2-------------");
E2.displayEmployee();
E2.CalculateSalary();
E2.CalculateSalary(0);
Employee.displayEmployeeCount();
}
}