Packages
Enumerations
Use
An enumeration that defines three shipping types
public enum ShippingType
{
UPS_NEXT_DAY,
UPS_SECOND_DAY,
UPS_GROUND
}
A statement that uses the enumeration and one of its constants
ShippingType secondDay = ShippingType.UPS_SECOND_DAY;
A method that uses the shipping enumeration as a parameter type
public static double getShippingAmount(ShippingType st)
{
double shippingAmount = 2.99;
if (st == ShippingType.UPS_NEXT_DAY)
shippingAmount = 10.99;
else if (st == ShippingType.UPS_SECOND_DAY)
shippingAmount = 5.99;
return shippingAmount;
}
A statement that calls this method
double shippingAmount =
getShippingAmount(ShippingType.UPS_SECOND_DAY);
// double shippingAmount2 = getShippingAmount(1); // Wrong type, not allowed