Practical-14
Write a Java Program to create an Employee class and generate Salary Slip for the employee.
Introdution
Java is an object-oriented programming language and provides users with an array of features to build robust applications. This program helps the user to create an employee class and generate a salary slip for the employee. This class is used to store information such as employee name, employee id, salary and also allows output objects in various formats such as CSV or HTML.
Code
import java.util.*;
public class Employee {
public String employeeName;
public int employeeNumber;
public int basicSalary;
public int salary;
public Employee(String name, int number, int salary) {
this.employeeName = name;
this.employeeNumber = number;
this.basicSalary = salary;
this.salary = salary;
}
public int calculateSalary() {
return this.salary + this.basicSalary;
}
public void generateSalarySlip() {
System.out.println("Salary Slip:");
System.out.println("Employee Name: " + this.employeeName);
System.out.println("Employee Number: " + this.employeeNumber);
System.out.println("Salary: " + this.salary);
}
}
Output
Salary Slip:
Employee Name: John Doe
Employee Number: 12345
Salary: 10000
The code above creates an Employee class which is used to store the details of an employee such as name, number and salary. It also has two functions; one for calculating the salary and one for generating the salary slip. The calculateSalary() function adds the basicSalary to the salary of the employee, and the generateSalarySlip() function prints out the salary slip for the employee.