public static void Main(string [] args) { CashSuper cs = CashFactory.CreateCashAccept(cbxType.SelectedItem.ToString()); double totalPrices = 0d; totalPrices = cs.acceptCash(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text) + totalPrices); total += totalPrices; }
public static void Main1(string[] args) { double total = 0.0d; CashSuper csuper = CashFactory.createCashAccept("80% discount"); double totalPrices = csuper.acceptCash(288 * 3); total = total + totalPrices; Console.WriteLine("Result : {0}", total); }
/// <summary> /// version 1.0 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //private void btnOk_Click(object sender, EventArgs e) //{ // double totalPrices = Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text); // total += totalPrices; // lbxList.Items.Add("单价:" + txtPrice.Text + " 数量:" + txtNum.Text + " 合计:" + totalPrices.ToString()); // lbResult.Text = total.ToString() + " 元"; //} /// <summary> /// version 1.1 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //private void btnOk_Click(object sender, EventArgs e) //{ // double totalPrices = 0d; // switch (cbxType.SelectedIndex) // { // case 0: // totalPrices = Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text); // break; // case 1: // totalPrices = Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text) * 0.8; // break; // case 2: // totalPrices = Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text) * 0.7; // break; // case 3: // totalPrices = Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text) * 0.5; // break; // } // total += totalPrices; // lbxList.Items.Add("单价:" + txtPrice.Text + " 数量:" + txtNum.Text +" " +cbxType.SelectedItem+ " 合计:" + totalPrices.ToString()); // lbResult.Text = total.ToString() + " 元"; //} /// <summary> /// version 1.2 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOk_Click(object sender, EventArgs e) { CashSuper csuper = CashFactory.createCashAccept(cbxType.SelectedItem.ToString()); double totalPrices = 0d; totalPrices = csuper.acceptCash(Convert.ToDouble(txtPrice.Text) * Convert.ToDouble(txtNum.Text)); total += totalPrices; lbxList.Items.Add("单价:" + txtPrice.Text + " 数量:" + txtNum.Text + " " + cbxType.SelectedItem + " 合计:" + totalPrices.ToString()); lbResult.Text = total.ToString() + " 元"; }
//得到现金促销计算结果(利用了多态机制,不同的策略行为导致不同的结果) public double GetResult(double money) { return(cs.acceptCash(money)); }
public double GetResule(double money) { return(cash.acceptCash(money)); }