Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

3.

A class called Employee, which models an employee with an ID, name and salary, is designed as
shown in the following class diagram. The method raise Salary (percent) increases the salary by the
given percentage. Develop the Employee class and suitable main method for demonstration.

public class Employee

private int employeeId;

private String name;

private double salary;

// Constructor

public Employee(int employeeId, String name, double salary)

this.employeeId = employeeId;

this.name = name;

this.salary = salary;

// Method to raise salary by a given percentage

public void raiseSalary(double percent)

if (percent > 0) {

salary += (salary * percent) / 100;

// Method to display employee information

public void displayEmployeeInfo()

System.out.println("Employee ID: " + employeeId);

System.out.println("Name: " + name);


System.out.println("Salary: $" + String.format("%.2f", salary));

// Main method for demonstration

public static void main(String[] args)

// Creating an Employee object

Employee employee1 = new Employee(1, "John Doe", 50000.0);

// Displaying initial employee information

System.out.println("Initial Employee Information:");

employee1.displayEmployeeInfo();

// Giving a salary raise of 10%

employee1.raiseSalary(10);

// Displaying updated employee information

System.out.println("\nEmployee Information after Salary Raise:");

employee1.displayEmployeeInfo();

You might also like