Page 113 - CTS - CSA TP - Volume 2
P. 113

COMPUTER SOFTWARE APPLICATION - CITS























           Explanation:

           1  Employee Class Definition
              •  The program begins by defining a class named Employee.
              •  This class encapsulates attributes such as name and salary.
              •  It also includes a method named raiseSalary designed to increase an employee’s salary by a specified
                 percentage.
           2  Create Employee Object and Print Current Salary
              •  Within the main method, an instance of the Employee class is created and named emp.
              •  The program prints the current salary of the employee (emp) to the console.

           3  Method to Raise Employee Salary
              •  A method named raiseEmployeeSalary is introduced.
              •  This method takes an Employee object and a percentage as parameters.
              •  Internally, it calls the raiseSalary method of the Employee object, leading to an increase in the salary.
           4  Raise Employee Salary in Main Method

              •  The raiseEmployeeSalary method is invoked within the main method, aiming to raise the salary of the
                 employee (emp) by 10%.
           5  Print Updated Salary

              •  Subsequently, the program prints the updated salary of the employee (emp) to reflect the changes made
                 by the raiseEmployeeSalary method.
           6  Conclusion

              •  This program serves as a practical example of how to pass objects, specifically instances of the Employee
                 class, to methods in Java.
              •  The design  of the Employee class, along  with the use of methods, illustrates  the principles  of object-
                 oriented programming (OOP), encapsulation, and the effective modification of object states.
                 This explanation aims to provide a conceptual understanding of the program without delving into the specific
                 code details. If you have further questions or need clarification on any specific aspect, feel free to ask!

















                                                           98

                               CITS : IT & ITES - Computer Software Application - Exercise 95
   108   109   110   111   112   113   114   115   116   117   118