1
0
Files
OAiP-Presnyakov_Ilya-Labora…/second/Payment.cs
2026-01-29 20:09:31 +03:00

83 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace second
{
public class Payment
{
public string FullName { get; set; }
public double Salary { get; set; }
public int HireYear { get; set; }
public double BonusPercent { get; set; }
public double IncomeTaxPercent { get; set; } = 13.0;
public int DaysWorked { get; set; }
public int WorkDaysInMonth { get; set; }
public double Accrued { get; private set; }
public double Withheld { get; private set; }
public Payment(
string fullName,
double salary,
int hireYear,
double bonusPercent,
int daysWorked,
int workDaysInMonth //, :(
)
{
FullName = fullName;
Salary = salary;
HireYear = hireYear;
BonusPercent = bonusPercent;
DaysWorked = daysWorked;
WorkDaysInMonth = workDaysInMonth;
}
public double CalcAccrued()
{
double basePay = Salary * DaysWorked / WorkDaysInMonth;
double bonus = basePay * (BonusPercent / 100.0);
Accrued = basePay + bonus;
return Accrued;
}
public double CalcWithheld()
{
double pension = Accrued * 0.01; // Im old, you know, like I saw the way dinosaurs died
double incomeTax = Accrued * (IncomeTaxPercent / 100.0);
Withheld = pension + incomeTax;
return Withheld;
}
public double CalcNet()
{
return Accrued - Withheld;
}
public int CalcXP()
{
int currentYear = DateTime.Now.Year;
int xp = currentYear - HireYear;
return xp;
}
public override string ToString()
{
return $"Name: {FullName}\nSalary: {Salary}\nXP: {CalcXP()} (HireYear is {HireYear})\nBonus: {BonusPercent}%\nIncomeTax: {IncomeTaxPercent}%\nWorkDaysInMonth: {WorkDaysInMonth} {(WorkDaysInMonth > 1 ? "days" : "day")}\nWorked: {DaysWorked}\nTotalAccrued: {CalcAccrued()}\nWithheld: {CalcWithheld()}\nActuallyAccrued: {CalcNet()}";
}
}
}