For this question, assume you are working on C# code in which you have already c
ID: 3762506 • Letter: F
Question
For this question, assume you are working on C# code in which you have already created an event handler method named btnCalculate_Click that contains a decimal variable named itemPrice. Paste or type into the space provided the following C# code:
1. The code for creating a private method named CalculateContractPrice that receives the itemPrice and uses it to calculate and return a decimal value that represents the price of the extended service contract that our company offers. Our company prices the service contracts as follows:
For an item with an itemPrice less than $100 the two year service contract price is $19.
For an item with an itemPrice from $100 to $299.99 the two year service contract price is $39.
For an item with an itemPrice greater than $299.99 the two year service contract price is 15% of the itemPrice.
2. The line(s) of code you need to add to the btnCalculate_Click event handler method to call the CalculateContractPrice method and place the value it returns into a variable named serviceContractPrice (assume this variable has already been declared).
Explanation / Answer
Design
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ContractPrice.aspx.cs" Inherits="CheggSpace.ContractPrice" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Item Price: <asp:TextBox ID="txtItemPrice" runat="server"></asp:TextBox><br/>
Service Contract Price:<asp:TextBox ID="txtServiceContractPrice" runat="server" ReadOnly="true"></asp:TextBox><br/>
<asp:Button ID="btnCalculate" runat="server" Text="Calculate Contract Price"/>
</div>
</form>
</body>
</html>
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CheggSpace
{
public partial class ContractPrice : System.Web.UI.Page
{
decimal itemPrice = 0.0M;
decimal serviceContract = 0.0M;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void btnCalculate_Click(object sender, EventArgs e)
{
txtServiceContractPrice.Text = "";
serviceContract = CalculateContractPrice(Decimal.Parse(txtItemPrice.Text));
txtServiceContractPrice.Text = "$"+ Convert.ToString(serviceContract);
}
private decimal CalculateContractPrice(decimal itemPrice)
{
decimal serviceContract = 0.0M;
if (itemPrice < 100.00M)
{
serviceContract = 19*itemPrice;
}
else if (itemPrice >= 100.00M && itemPrice <= 299.99M)
{
serviceContract = 39*itemPrice;
}
else if (itemPrice > 299.99M)
{
serviceContract = 15*itemPrice;
}
return serviceContract;
}
}
}
Note: I create .aspx page i.e Web Form
it consists of Design and Code , i consider CalculateContractPrice(decimal itemPrice)
i took two text boxes i.e txtItemPrice accepts item price and txtServiceContractPrice gives result.
and btnCalculate click gives result to us.
I use C# Framework 4.5 ,if any queries or help , send comments
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.