javaprogram3
javaprogram3
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 raiseSalary(percent) increases the salary by the
given percentage. Develop the Employee class and suitable main method for demonstration.
Java Code:
this.id = id;
this.name = name;
this.salary = salary;
if (percent > 0) {
salary += raiseAmount;
System.out.println(name + "'s salary raised by " + percent + "%. New salary: $" + salary);
} else {
return "Employee ID: " + id + ", Name: " + name + ", Salary: $" + salary;
System.out.println(employee);
employee.raiseSalary(10);
System.out.println(employee);
In this example, the Employee class has a constructor to initialize the employee’s ID, name, and
salary. The raiseSalary method takes a percentage as a parameter and raises the salary
the Employee object. The main method demonstrates the usage of the Employee class by creating
an instance, displaying its details, raising the salary, and then displaying the updated details.
Output: