A Java method cannot update primitive type parameters. For example, the following program cannot work as intended:
public class BonusTester
{
public static void applyBonus(double value, double bonus)
{
value = value * (1 + bonus);
}
public static void main(String[] args)
{
double sal = 45000;
applyBonus(sal, 0.02); // 2% bonus; cannot work
System.out.println(sal);
System.out.println("Expected: 45900.0");
}
}
To address this problem, the salary should be an object of a class.