second ex
This commit is contained in:
82
second/Payment.cs
Normal file
82
second/Payment.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
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; // I’m 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()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user