예제 #1
0
 protected void btnCalculate_Click(object sender, EventArgs e)
 {
     double amount = 0;
     bool goodAmount = double.TryParse(txtAmount.Text, out amount);
     if (!goodAmount)
     {
         Response.Write("<script>alert('Please enter a valid amount');</script>");
         txtAmount.Text = "";
         txtAmount.Focus();
         return;
     }
     double percent = 0;
     if (rdbPercentage.SelectedItem.Text != "other")
     {
         percent = double.Parse(rdbPercentage.SelectedValue.ToString());
     }
     else
     {
         bool goodPercent = double.TryParse(txtOther.Text, out percent);
         if (!goodPercent)
         {
             Response.Write("<script>alert('Please enter a valid Percentage');</script>");
             txtAmount.Text = "";
             txtAmount.Focus();
             return;
         }
     }
     TipCalculator Tip = new TipCalculator(amount, percent);
     lblTip.Text = Tip.CalculateTip().ToString("$##0.##");
     lblTotal.Text = Tip.CalculateTotal().ToString("$##0.##");
 }
예제 #2
0
        public void TestTotalCalcuation()
        {
            double total = tc.CalculateTotal();

            Assert.AreEqual(129.5, total);
        }