PayrollWithMethod Program
Description
We have already studied Payroll program in Fundamentals section.In this section, we incorporate two methods in the program:
calculatePayroll method calculates and returns the weekly pay
based on the passed parameters of hours worked and hourly wage.
printPayroll method prints the payroll report.
printPayroll method prints the payroll report.
The program also demonstrates the concept of global constants.
Associated Concepts:
Method
Global constants
Global constants
Algorithm:
Define global constants so that they are accessible by all the methods
in the program.
main method:
calculatePayroll method definition:
printPayroll method definition:
main method:
Declare local variables
Input data from the keyboard
Call calculatePayroll method and pass arguments to get the weekly pay
Call printPayroll method and pass arguments to print the payroll report
Input data from the keyboard
Call calculatePayroll method and pass arguments to get the weekly pay
Call printPayroll method and pass arguments to print the payroll report
calculatePayroll method definition:
The method has two parameters to represent the hours worked
and base wage.
It returns the weekly pay as a double value.
It returns the weekly pay as a double value.
printPayroll method definition:
The method has five parameters to represent the first name,
last name, hours worked, base wage, and weekly pay.
It prints the payroll report without returning anything.
It prints the payroll report without returning anything.