1using System;
2
3namespace AmericanSalary
4{
5 /**//// <summary>
6 /// 公用的常量
7 /// </summary>
8 public class Constant
9 {
10 public static double BASE_SALARY = 4000;
11 }
12}
13
1using System;
2
3namespace AmericanSalary
4{
5 /**//// <summary>
6 /// 計算美國個人獎金
7 /// </summary>
8 public class AmericanBonus
9 {
10 public double Calculate()
11 {
12 return Constant.BASE_SALARY * 0.1;
13 }
14 }
15}
16
1using System;
2
3namespace AmericanSalary
4{
5 /**//// <summary>
6 /// 計算美國個人所得稅
7 /// </summary>
8 public class AmericanTax
9 {
10 public double Calculate()
11 {
12 return (Constant.BASE_SALARY + (Constant.BASE_SALARY * 0.1)) * 0.4;
13 }
14 }
15}
16
客戶端的調用代碼:
1
2using System;
3
4namespace AmericanSalary
5{
6 /**//// <summary>
7 /// 客戶端程序調用
8 /// </summary>
9 public class Calculator
10 {
11 public static void Main(string[] args)
12 {
13 AmericanBonus bonus = new AmericanBonus();
14 double bonusValue = bonus.Calculate();
15
16 AmericanTax tax = new AmericanTax();
17 double taxValue = tax.Calculate();
18
19 double salary = 4000 + bonusValue - taxValue;
20
21 Console.WriteLine("American Salary is:" + salary);
22 Console.ReadLine();
23 }
24 }
25}
26
運行程序,輸入的結果如下:
American Salary is:2640