Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 73 additions & 82 deletions gross-to-net/README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,75 @@
# Gross-to-net Pay Check Coding Challenge

Requirements:

- Calculate the net pay as follows: net pay = taxable earnings - pre-tax deductions - taxes - post-tax deductions + non-taxable earnings
- Earning types
- Salary earnings are defined by a flat `amount`
- Hourly earnings are defined by an amount of `hours` and a `rate`
- Earnings that are not taxable are not withheld by deductions or taxes
- Pre-tax deductions are based on gross taxable-pay
- Flat vs percentage deductions (percentages encoded as `value / 100`)
- Taxes are based on gross taxable-pay less pre-tax deductions
- Taxes with a cap should not be withheld above the cap
- Post-tax deductions are based on gross taxable-pay less pre-tax deductions and taxes
- Deduction and tax priority
- When taxable earnings are less than deductions and taxes, withholding priority is as follows: pre-tax deductions before taxes before post-tax deductions.
- For each deduction and tax, a higher `priority` value indicates this item should be withheld first.
- If a deduction or tax is cannot be withheld to the full amount, the deficit is recorded.
- Output the following
- Gross pay
- Net pay to employee
- Amounts withheld for deductions and taxes by code with deficits

Sample input object:

```json
{
"earnings": [
{
"code": "overtime",
"type": "hourly",
"hours": 20,
"rate": 15,
"isTaxable": true
},
{
"code": "regular",
"type": "hourly",
"hours": 20,
"rate": 13,
"isTaxable": false
},
{
"code": "bonus",
"type": "salary",
"amount": 1500,
"isTaxable": true
}
],
"deductions": [
{
"code": "401k",
"type": "percentage",
"priority": 1,
"value": 10,
"isPreTax": false
},
{
"code": "healthInsurance",
"type": "flat",
"priority": 2,
"value": 20,
"isPreTax": true
}
],
"taxes": [
{
"code": "federalIncome",
"type": "percentage",
"priority": 1,
"value": 10
},
{
"code": "fica",
"type": "cappedPercentage",
"priority": 2,
"value": 10,
"cap": 50
}
]
}
# Gross-to-Net Payroll Calculator

Implement the `Calculate` method in `PayrollCalculator.cs` which accepts three collections as arguments... `earnings`, `deductions`, and `taxes` then returns a `PayrollResult` with `grossPay`, `grossTaxableEarnings`, a list of `witholdings`, and `netPay`.
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "witholdings" should be "withholdings".

Copilot uses AI. Check for mistakes.

## Requirements

### NetPay Calculation

`NetPay = GrossTaxableEarnings - PreTaxDeductions - Taxes - PostTaxDeductions + NonTaxableEarnings`

### Earnings

- Types: `salary`, `hourly`
- Salary earnings have a flat `amount`
- Hourly earnings amount is `hours × rate`
- Only taxable earnings are included when calculating deductions/taxes

### Deductions

- Types: `flat`, `percentage`
- Flat decductions have a fixed dollar `value`
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "decductions" should be "deductions".

Suggested change
- Flat decductions have a fixed dollar `value`
- Flat deductions have a fixed dollar `value`

Copilot uses AI. Check for mistakes.
- Percentage deductions are calculated as `value / 100` of basis
- Pre-tax deductions reduce tax basis, calculated with gross taxable earnings
- Post-tax deductions do not reduce tax basis

### Taxes

- Types: `percentage`, `cappedPercentage`
- Percentage taxes are calculated as `value / 100` of basis using (gross taxable earnings - pre-tax deductions)
- Capped Percentage has a max value defined by the `cap` property

### Witholdings

- Types: `tax`, `deductions`
- Deductions are either Pre-Tax or Post-Tax depending on the `isPrefix` value.
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation error: The property is named isPreTax (not isPrefix). This should be corrected to match the actual model property in Deduction.cs.

Suggested change
- Deductions are either Pre-Tax or Post-Tax depending on the `isPrefix` value.
- Deductions are either Pre-Tax or Post-Tax depending on the `isPreTax` value.

Copilot uses AI. Check for mistakes.
- Witholding groups are applied using the following order:
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "Witholding" should be "Withholding".

Suggested change
- Witholding groups are applied using the following order:
- Withholding groups are applied using the following order:

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +36
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "Witholdings" should be "Withholdings".

Suggested change
### Witholdings
- Types: `tax`, `deductions`
- Deductions are either Pre-Tax or Post-Tax depending on the `isPrefix` value.
- Witholding groups are applied using the following order:
### Withholdings
- Types: `tax`, `deductions`
- Deductions are either Pre-Tax or Post-Tax depending on the `isPrefix` value.
- Withholding groups are applied using the following order:

Copilot uses AI. Check for mistakes.
- PreTax Deductions
- Taxes
- PostTax Deductions
- Within each group, withholdings are applied in order of their `priority` value (highest `priority` first)
- When a withholding exceeds available earnings the difference is added as a `deficit` as NetPay cannot go below zero.

## Build and Run

To test your solution, Program.main() contains a test harness for loading test data from a json file and comparing the expected output to the actual output provided by your `Calculate` method and report the result.

A json file containing basic test cases is included in the project, `test-cases.json`, but you are encouraged to add additional test cases as needed. Additional test cases may be used to verify edge cases and common defects during your interview.

### IDE

An online VSCode codespace will be used during assesmments and candidates are free to install extensions available in the vs code default extension marketplace.
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "assesmments" should be "assessments".

Suggested change
An online VSCode codespace will be used during assesmments and candidates are free to install extensions available in the vs code default extension marketplace.
An online VSCode codespace will be used during assessments and candidates are free to install extensions available in the vs code default extension marketplace.

Copilot uses AI. Check for mistakes.

Start Debug: `F5`

### Commmand-line
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "Commmand-line" has an extra 'm' and should be "Command-line".

Suggested change
### Commmand-line
### Command-line

Copilot uses AI. Check for mistakes.

Navigate to the project root e.g. `gross-to-net/dotnet/` then use _dotnet_ CLI commands.

Building from CLI

```ps
dotnet build
```

Running from CLI

```ps
dotnet run
```

All test cases and solutions can be found in `test-cases.json`
Show Help Text

```ps
dotnet run -- --help
```
64 changes: 64 additions & 0 deletions gross-to-net/directory-structure.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Folder PATH listing for volume Windows
Volume serial number is 7EA5-7906
C:.
| advanced-test-cases.json
| directory-structure.txt
| input.json
| INTERVIEWER_README.md
| README.md
| test-cases.json
|
\---dotnet
| GrossToNet.csproj
| PayrollCalculator.cs
| Program.cs
|
+---bin
| \---Debug
| \---net8.0
| advanced-test-cases.json
| GrossToNet.deps.json
| GrossToNet.dll
| GrossToNet.exe
| GrossToNet.pdb
| GrossToNet.runtimeconfig.json
| input.json
| test-cases.json
|
+---models
| Deduction.cs
| Earning.cs
| PayrollData.cs
| PayrollResult.cs
| Tax.cs
| Withholding.cs
|
\---obj
| GrossToNet.csproj.nuget.dgspec.json
| GrossToNet.csproj.nuget.g.props
| GrossToNet.csproj.nuget.g.targets
| project.assets.json
| project.nuget.cache
|
\---Debug
\---net8.0
| .NETCoreApp,Version=v8.0.AssemblyAttributes.cs
| apphost.exe
| GrossToNet.AssemblyInfo.cs
| GrossToNet.AssemblyInfoInputs.cache
| GrossToNet.assets.cache
| GrossToNet.csproj.CoreCompileInputs.cache
| GrossToNet.csproj.FileListAbsolute.txt
| GrossToNet.dll
| GrossToNet.GeneratedMSBuildEditorConfig.editorconfig
| GrossToNet.genruntimeconfig.cache
| GrossToNet.GlobalUsings.g.cs
| GrossToNet.pdb
| GrossToNet.sourcelink.json
|
+---ref
| GrossToNet.dll
|
\---refint
GrossToNet.dll

9 changes: 5 additions & 4 deletions gross-to-net/dotnet/GrossToNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Content Include="../input.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Content Include="test-cases.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
</ItemGroup>
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Inconsistent indentation: The closing </ItemGroup> tag has inconsistent indentation compared to line 11. It should align with the opening tag.

Suggested change
</ItemGroup>
</ItemGroup>

Copilot uses AI. Check for mistakes.
</Project>
20 changes: 20 additions & 0 deletions gross-to-net/dotnet/PayrollCalculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using GrossToNet.Models;

namespace GrossToNet;

/// <summary>
/// Payroll calculator that processes earnings, deductions, and taxes to compute net pay.
///
/// CALCULATION: Net pay = gross pay - pre-tax deductions - taxes - post-tax deductions
///
/// See README.md for detailed requirements and examples.
/// </summary>
public class PayrollCalculator
{
public PayrollResult Calculate(IEnumerable<Earning> earnings, IEnumerable<Deduction> deductions, IEnumerable<Tax> taxes)
{

// TODO: Implement payroll calculation logic here
throw new NotImplementedException("Payroll calculation not yet implemented. Please implement the Calculate method.");
}
}
Loading