Page 111 - CITS - CSA - TP (Volume 2) - Hindi
P. 111

कं  ूटर सॉ वेयर ए ीके शन - CITS




           टा  3: कम चारी वेतन अपडेट करना
              class Employee {

                  String name;
                  double salary;

                  Employee(String name, double salary) {
                      this.name = name;

                      this.salary = salary;
                  }

                  // Method to raise the salary of an employee by a given percentage
                  void raiseSalary(double percentage) {

                      double raiseAmount = salary * (percentage / 100);

                      salary += raiseAmount;
                  }
              }

              public class RaiseSalaryDemo {

                  public static void main(String[] args) {
                      // Create an Employee object

                      Employee emp = new Employee(“John”, 50000);



                      // Print current salary
                      System.out.println(“Current salary of “ + emp.name + “: “ + emp.salary);



                      // Call the method to raise the salary by 10%

                      emp.raiseSalary(10);



                      // Print updated salary

                      System.out.println(“Updated salary of “ + emp.name + “: “ + emp.salary);
                  }
              }

           आउटपुट:














                                                           97

                                   CITS : IT & ITES - कं  ूटर सॉ वेयर ए ीके शन - अ ास 95
   106   107   108   109   110   111   112   113   114   115   116