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 - Java Tutorial
From the course: Learning Java 11
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
What are functions? (conceptually)4m 25s
-
(Locked)
Defining functions in Java3m 28s
-
(Locked)
Calling functions in Java5m 9s
-
(Locked)
Parameters in Java5m 30s
-
(Locked)
Return types in Java5m 34s
-
(Locked)
Using built-in functions in Java4m 43s
-
(Locked)
Challenge: Salary calculator1m 21s
-
(Locked)
Sample solution: Salary calculator3m 46s
-
(Locked)
-
-