Hello! I\'m trying to figure out how to create the code for this solution to wor
ID: 3921395 • Letter: H
Question
Hello! I'm trying to figure out how to create the code for this solution to work properly. It's basically asking me to create a text box that will calculate commission when sales amount is typed into it. Any help would be greatly greatly appreciated and thank you so much in advance!
1. Create a new web form in the Demos folder. Name the new form CalcCommission.aspx, make sure you have a code behind.
2. In the App_Code folder, create a class file named Commission. This class should contain at least 4 methods which calculate commissions based on the amount of sales and returns a value. Sales greater than $50,000 commission is 20% of sales. Sales between $40,000 and 49999 commission is 15% of sales. Sales between $30,000 and 39999 commission is 10% of sales. Sales between $20,000 and 29999 commission is 5% of sales. Sales less than $20,000, commission is 0.
3. Have the user enter a sales amount, use a decision making structure to call the correct method in the Commission.cs. Commision.cs should return the commission amount. The commission amount should be displayed on the web form.
Explanation / Answer
commission.cs in App_Code Folder
class Commission
{
public double CalculateComm1(double sales)
{
return (sales * 0.2);
}
public double CalculateComm2(double sales)
{
return (sales * 0.15);
}
public double CalculateComm3(double sales)
{
return (sales * 0.1);
}
public double CalculateComm4(double sales)
{
return (sales * 0.05);
}
public double CalculateComm5(double sales)
{
return 0;
}
}
CalcCommission.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Commission c=new Commission();
double comm=0;
double sales = Convert.ToDouble(TextBox1.Text);
if (sales > 50000)
comm = c.CalculateComm1(sales);
if (sales > 40000 && sales<49999)
comm = c.CalculateComm2(sales);
if (sales > 30000 && sales <39999)
comm = c.CalculateComm3(sales);
if (sales > 20000 && sales <29999)
comm = c.CalculateComm4(sales);
if (sales < 20000)
comm = c.CalculateComm5(sales);
TextBox2.Text = comm.ToString();
}
}
}
CalcCommision.aspx
<!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 />
Enter sales
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
Commission=<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server"
Text="Calculate Commission" />
</div>
</form>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.