public Product Split(int quantity=0)
{
Product product = new Product(this.Model, this.Price);
// if the some of the quantity of this product is being shared with the new product
if (quantity > 0)
{
// Remove the desired quantity from this product
this.Quantity -= quantity;
// If there wasn't enough in this product category
if (this.Quantity < 0)
{
// Add to the new product whatever quantity is available
product.Quantity = quantity + this.Quantity;
this.Quantity = 0; // This product category is now empty
}
else
{
// Otherwise, split the amount of available quantity in the desired amount
product.Quantity = quantity;
}
}
// Reference to a new product
return product;
}