Skip to content

Instantly share code, notes, and snippets.

@bolenton
Created September 12, 2015 03:50
Show Gist options
  • Save bolenton/c4ed89bb544f8ab3c74c to your computer and use it in GitHub Desktop.
Save bolenton/c4ed89bb544f8ab3c74c to your computer and use it in GitHub Desktop.
using System;
namespace ChallengePostalCalculator
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void GroundButton_CheckedChanged(object sender, EventArgs e)
{
double groundFare = 0.15;
try
{
calculateParcel(groundFare);
}
catch
{
resultLabel.Text = "Please enter all specs!!";
}
}
protected void AirButton_CheckedChanged(object sender, EventArgs e)
{
double airFare = 0.25;
try
{
calculateParcel(airFare);
}
catch
{
resultLabel.Text = "Please enter all specs!";
}
}
protected void NextDayButton_CheckedChanged(object sender, EventArgs e)
{
double nextDayFare = 0.45;
try
{
calculateParcel(nextDayFare);
}
catch
{
resultLabel.Text = "Please enter all specs!!";
}
}
private void calculateParcel(double fareMultiplier)
{
string myWidth = widthTextBox.Text;
string myHeight = heightTextBox.Text;
string myLength = lengthTextBox.Text;
double fare = fareMultiplier;
double result = (double.Parse(myWidth) * double.Parse(myHeight)) * fare;
double resultWithLength = (double.Parse(myWidth) * double.Parse(myHeight) * double.Parse(myLength)) * fare;
if (!String.IsNullOrEmpty(myWidth.ToString()) & !String.IsNullOrEmpty(myHeight.ToString()) & !String.IsNullOrEmpty(myHeight.ToString()))
{
resultLabel.Text = result.ToString();
}
else if (!String.IsNullOrEmpty(myWidth.ToString()) & !String.IsNullOrEmpty(myHeight.ToString()))
{
resultLabel.Text = result.ToString();
}
else
{
resultLabel.Text = "bob";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment