Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that calculates tip amount from a restaurant bill. You enter the

ID: 3538332 • Letter: W

Question

Write a program that calculates tip amount from a restaurant bill. You enter the bill amount and the program will calculate the tax (10%) and fill out the amount for Tax and Total before Tip. Tip Percent is a Combo box which you select a tip percentage. The tip percentage will be typed in the Item property of Tip Percent Combo box. Once tip percent has been selected, you can click on the button (Calculate Tip) to display the tip.
In this program, you will create a heading label, 5 labels associated with 5 text boxes and one button. See the figure below as reference. You need to create 2 event handlers which are
1. Bill Amount text box TextChanged event
a. Validate the number is not negative
b. Validate the input is number, not letters
c. Once a good input is received, update the tax box, bill before tip box
2. Calculate tip button Click event
a. Validate bill amount has been entered
b. Validate that Tip percentage has been selected
c. Calculate tip and display it in tip text box.
Some other property changes
1. The textbox for tax, bill before tip, and tip should be read only
2. Tip percentage are fixed 3 values, 15%, 18% and 20%
Create

Explanation / Answer

code behind :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        int intAmount = int.Parse(TextBox1.Text);
        if (intAmount <= 0)
        {
            Label1.Visible = true;
            TextBox1.Text = "";
            Label1.Text = "Should be non negative Number";

        }
        else
        {
            Double tax = intAmount + 0.10 * intAmount;
            tax = Double.Parse(TextBox2.Text);
        }

    }



    protected void Button1_Click(object sender, EventArgs e)
    {
        if (DropDownList1.SelectedItem.Text == "10%")
        {
            Double tip = int.Parse(TextBox2.Text) + 0.10 * int.Parse(TextBox2.Text);
            tip = Double.Parse(TextBox3.Text);
        }
    }
}


.aspx file


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <br />
        <br />
        <br />
&nbsp;&nbsp;&nbsp; Amount :&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
            ControlToValidate="TextBox1" ErrorMessage="* should not be empty"
            SetFocusOnError="True"></asp:RequiredFieldValidator>
        <asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
            ControlToValidate="TextBox1" ErrorMessage="should be no only"
            ValidationExpression="^d+$"></asp:RegularExpressionValidator>
        <br />
        <br />
        Amount+Tax :
        <asp:TextBox ID="TextBox2" runat="server" ReadOnly="True"></asp:TextBox>
        <br />
        <br />
       Tip % :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem>--Select--</asp:ListItem>
            <asp:ListItem>10%</asp:ListItem>
            <asp:ListItem>18%</asp:ListItem>
            <asp:ListItem>20%</asp:ListItem>
            <asp:ListItem></asp:ListItem>
        </asp:DropDownList>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
            ControlToValidate="DropDownList1" ErrorMessage="* should not be empty"
            SetFocusOnError="True"></asp:RequiredFieldValidator>
        <br />
        <br />
&nbsp;Total :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox3" runat="server" ReadOnly="True"></asp:TextBox>
        <br />
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server"
            Text="Calculate tip" />
   
    </div>
    </form>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote