示例
//CalculateTax method to calculate tax
/*cost <= 20000 then tax = 10%
cost > 20000 then tax = 12.5%*/
public void CalculateTax(double percentage = 4.5)
{
//create local variable
double t;
//calculate tax
if (this.cost <= 20000)
{
t = cost * 10 / 100;
}
else
{
t = cost * percentage / 100;
}
tax = t;
}
public void CalculateTax(double cost, double percentage)
{
//create local variable
double t;
//calculate tax
if (cost <= 50000)
{
t = cost * 5 / 100;
}
else
{
t = cost * percentage / 100;
}
tax = t;
}