← Back to Week 1 Hub

Payroll Calculator

Calculate an employee's gross pay with overtime support

Workbook 1c, p.88 — Project name: payroll-calculator

In Plain English

Build a payroll calculator. Ask for an employee's name, how many hours they worked, and their hourly pay rate. If they worked more than 40 hours, the extra hours are paid at 1.5 times the normal rate (overtime). Display their name and total gross pay.

What a Successful Run Looks Like

Run 1 — With Overtime

Enter your name: Alice Enter hours worked: 45 Enter pay rate: 20 Name: Alice Gross Pay: $950.00

40 regular hours at $20 = $800, plus 5 overtime hours at $30 (1.5x) = $150. Total: $950.00

Run 2 — No Overtime

Enter your name: Bob Enter hours worked: 35 Enter pay rate: 15 Name: Bob Gross Pay: $525.00

35 hours at $15 = $525.00. No overtime because hours did not exceed 40.

Key detail: The overtime threshold is 40 hours. Only the hours beyond 40 get the 1.5x rate — the first 40 hours are always paid at the normal rate.
What This Exercise Practices

This exercise reinforces these concepts from Week 1:

Why this matters: This is your first exercise that combines user input, conditional logic, and formatted output all in one program. Getting comfortable with this pattern prepares you for more complex projects later.
Flow Diagram
Step 1 Ask for name Scanner input
Step 2 Ask for hours Scanner input
Step 3 Ask for pay rate Scanner input
Check Over 40 hours?
Yes
Calculate with overtime 40 x rate + extra x 1.5 x rate
No
Calculate normally hours x rate
Output Display name and gross pay Formatted with $

Think about which data types to use for hours and pay rate. Does your output need to show dollar signs and decimal places?

← Basic Calculator Sandwich Shop →