Total Salaries code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Total Salaries code

I'm getting this error message with this code: "method CalculateTotalSalary in class Program cannot be applied to given types;" 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 total = worker1.salary+worker2.salary; return total; } } class Worker{ public String name; public int salary; }

11th Nov 2021, 5:21 AM
Natanael
3 Answers
+ 1
Natanael Your method should have 2 parameters of type int salary1 and salary2 public static int CalculateTotalSalary(int salary1, int salary2){ int total = salary1 + salary2; return total; }
11th Nov 2021, 5:30 AM
A͢J
A͢J - avatar
0
Thank you, I would have never figured this out because there's no mention of salary1 and salary2 within the lessons or instructions
11th Nov 2021, 5:35 PM
Natanael
0
I am getting errors saying i meed a comma, a close parentheses, or a close square bracket in line 0 (??)
9th Mar 2022, 4:57 PM
Chris
Chris - avatar