I'm attempting to create a function that will select the correct carton based on the qty of the carton content.
Here are my cartons that have the number of items they can hold:
SMALL_PASCAL = 300 BIG_PASCAL = 600 BABY_BOX = 1200 A485_1201 = 1800 A4140_1901 = 3000 A485 = 5000
And here is the method that will return the CartonType
:
/// <summary>
/// Get Carton Type
/// </summary>
/// <param name="qty"></param>
/// <returns></returns>
[Test]
private static CartonType GetCartonType(int qty)
{
if (qty <= 300)
{
return CartonType.SMALL_PASCAL;
}
else if (qty > 300 && qty <= 600)
{
return CartonType.SMALL_PASCAL;
}
else if (qty > 600 && qty <= 1200)
{
return CartonType.BABY_BOX;
}
else if (qty > 1200 && qty <= 1800)
{
return CartonType.A485_1201;
}
else if (qty >1800 && qty <=3000)
{
return CartonType.A4140_1901;
}
else // 5000 or more.
{
return CartonType.A485;
}
}
Calling the method like so:
int qty = 1540;
Console.WriteLine(GetCartonType(qty));
Output:
A485_1201
Is there a better way to achieve this rather than an if
statement? Also, I just had a thought that what if the qty is like 10,000? I would then require 2 A485.