COMP2243 - Programming and Problem Solving

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Methods RightTriangle.java RightTriangleWithLoop.java Geometry.java PayrollWithMethod.java PayrollWithMethodLoop.java Palindrome.java GlobalAndLocal.java Overloading.java Overloading2.java MathMethods.java and MathProgram.java CaesarCipher.java



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.

The program also demonstrates the concept of global constants.

Associated Concepts:

Method

Global constants

Algorithm:

Define global constants so that they are accessible by all the methods in the program.

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

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.

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.

Source Code



Sample Run




Video