0
Need help to solve this practice
Hi I donât know how to solve this: Should output worker1.salary+worker2.salary Need explanation how to do it please ! Thx public class Program { public static void main(String[] args) { //James Worker worker1 = new Worker(); worker1.name = "James"; worker1.salary = 200000; //Tom Worker worker2 = new Worker(); worker2.name = "Tom"; worker2.salary = 150000; System.out.println(CalculateTotalSalary(worker1.salary,worker2.salary)); } //complete the function to calculate the total salary public static int CalculateTotalSalary(int salery) } } public class Worker{ private String name; private int salary; }
7 Answers
+ 2
Please make a properly indentated code in code playground and paste the link of the code here... its difficult to read/debug codes in text format
+ 1
For starters your method to calculate the salary has 1 parameter, but received 2 arguments (parameter values).
Fix that and then just add a+b and return it.
+ 1
public class Program
{
public static void main(String[] args) {
//James
Worker worker1 = new Worker();
worker1.name = "James";
worker1.salary = 200000;
//Tom
Worker worker2 = new Worker();
worker2.name = "Tom";
worker2.salary = 150000;
System.out.println(CalculateTotalSalary(worker1.salary,worker2.salary));
}
//complete the function to calculate the total salary
public static int CalculateTotalSalary(int a,int b){return a+b;}
}
public class Worker{
public String name;
public int salary;
}
0
RKK posted the code for you please help thanks
0
Your calculate function was calculateTotalSalary (int a)
But when called you were passing 2 arguments, calculateTotalSalary (a,b)
You just had to make the function definition accept 2 arguments
- 1
Anastacia Ru i dont know what to do please help more thanks