ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

C# 员工年度薪资与税务计算器

C# 员工年度薪资与税务计算器 定义一个类 Employee包含string Name员工姓名double BaseSalary每月基本工资double[] MonthlyRatios当月实际工资 BaseSalary * MonthlyRatios[i]在类中实现以下方法double GetAnnualGross()遍历 MonthlyRatios 数组计算 12 个月税前总收入。double GetTax()假设个税规则为年收入中超过 60000 的部分才需要缴税税率为 10%。要求使用 Math.Max(0, 年收入 - 60000) * 0.1 计算税款如果年收入不到 60000则税款为 0。double GetAnnualNet()计算税后年收入即 GetAnnualGross() - GetTax()。结果使用 Math.Round(值, 2) 保留两位小数。int FindBestMonth()遍历数组找出绩效系数最高的月份返回 1~12遍历时配合 Math.Max() 来记录当前最大系数。string GetPayslip()使用字符串插值 $... 返回工资条写一个静态方法 static string GetCompanyTopEarner(Employee[] staff)遍历数组比较所有员工的 税后年收入找出税后收入最高的人返回字符串 公司年度税后收入最高的是XXX。比较时要求使用 Math.Max()。在 Main 方法中创建一个 Employee[] 数组存放 3 名员工的数据。用 foreach 遍历该数组调用 GetPayslip() 打印每名员工的工资条。using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace work_员工年度薪资与税务计算器 { internal class Program { static void Main(string[] args) { Employee[] employe new Employee[] { new Employee(张三,8000.00,new double[]{1.2,1,1.3,0.9,0.7,0.8,1.1,1.2,1.4,1,0.8,0.7}), new Employee(李四,7000.00,new double[]{1.2,1,1.3,0.9,0.7,0.8,1.1,1.2,1.4,1,0.8,0.7}), new Employee(王五,8800.00,new double[]{1.2,1,1.3,1.4,0.7,0.8,1.1,1.2,1.4,1,0.8,0.7}) }; foreach (Employee emp in employe) { Console.WriteLine(emp.GetPayslip()); } Console.WriteLine(GetCompanyTopEarner(employe)); } static string GetCompanyTopEarner(Employee[] staff) { if (staff null || staff.Length 0) return 公司暂无员工数据; Employee topEarner staff[0]; double maxNet topEarner.GetAnnualNet(); for (int i 1; i staff.Length; i) { double currentNet staff[i].GetAnnualNet(); if (Math.Max(currentNet, maxNet) currentNet) { maxNet currentNet; topEarner staff[i]; } } return $公司年度税后收入最高的是:{topEarner.Name}; } } }
返回列表