From the course: Learning Java 11

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Sample solution: Salary calculator

Sample solution: Salary calculator - Java Tutorial

From the course: Learning Java 11

Start my 1-month free trial

Sample solution: Salary calculator

(bouncy music) - Let's look at one way, we can create a function that calculates an employee's salary in java. Your function may look different and that's ok. There are many different solutions to this challenge. For the function, we return a double but you could return an INT, as long as it's numerical. We also make both of our parameters doubles as well. You could make them INTs, but it limits your functionality. In the implementation between the curly brackets, the first thing we do is calculate the weekly paycheck. We multiply the number of hours worked per week, by the amount the employee makes per hour. In the next step, we return the yearly salary by multiplying the weekly paycheck times 52. In this case, we are assuming the employee works every week during the year. To call the function, we use the functions name, "Salary Calculator". In this example, we say, "The employee works 40 hours per week and makes $15 an hour." We save the result of this function call, in a variable…

Contents