0

I am trying to update the value of salary using my method computeTotalSalary which is doing the job but salary remains the same when using it in another function. I have tried declaring salary with static, still not working.

Main class

public class main {
    
    public static void main(String[] args) {
        
        double salary = 35000;
        int years = 10;
    
        System.out.println(PayrollLibrary.computeTotalSalary(salary, years));
        
        PayrollLibrary.displaySalary("hans", "junior", salary);
        

    }
    
}

PayrollLibrary

public class PayrollLibrary {
    
    

    public static double computeTotalSalary(double salary, int years) {
        
        if(years < 5) {
            return (salary*105/100);
        }
        else if(years>=5 && years <=10)
        {
            return (salary*110/100);

        }
        else {
            return salary += 5000; 

        }
    }
        
        
        public static void displaySalary(String fName, String lName, double salary) {
        
            System.out.println("Employee "+ fName +" " + lName + "earns Rs " + salary);
        }
        
        
}

0 Answers0