Skip to content

Instantly share code, notes, and snippets.

@NamXH
Created October 13, 2016 18:51
Show Gist options
  • Select an option

  • Save NamXH/60de920892a6bb75cfe4ffc8f1bbe031 to your computer and use it in GitHub Desktop.

Select an option

Save NamXH/60de920892a6bb75cfe4ffc8f1bbe031 to your computer and use it in GitHub Desktop.
public static class CartonConstants
{
public static readonly int LengthInInch = 18;
public static readonly int WidthInInch = 18;
public static readonly int HeightInInch = 8;
}
public class Solution
{
public bool ValidateLength(string lengthStr)
{
var length = 0f;
if (float.TryParse(lengthStr, out length) && length > 0)
{
return true;
}
else
{
return false;
}
}
public bool ValidateInput(string lengthStr, string widthStr, string heightStr)
{
if (ValidateLength(lengthStr) && ValidateLength(widthStr) && ValidateLength(heightStr))
{
return true;
}
else
{
return false;
}
}
public int GetNumberOfCartons(float lengthInFt, float widthInFt, float heightInFt)
{
var FtToInch = 12;
return (int)(lengthInFt * FtToInch / CartonConstants.LengthInInch) * (int)(widthInFt * FtToInch / CartonConstants.WidthInInch) * (int)(heightInFt * FtToInch / CartonConstants.HeightInInch);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment