Classe:
public class Product
{
public string Name { get; set; }
private int QuantityStock { get; set; }
public Product(string name, int quantityStock)
{
Name = name;
QuantityStock = quantityStock;
}
public void remove_from_stock(int quantityRemove)
{
if (quantityRemove < QuantityStock)
{
Console.WriteLine($"Withdrawal of {quantityRemove} units successfully completed.");
QuantityStock -= quantityRemove;
return;
}
Console.WriteLine($"Error: Insufficient stock for withdrawal of {quantityRemove} units.");
}
public void display_stock()
{
Console.WriteLine($"Product: {Name} - Stock: {QuantityStock}");
}
}
Instância:
Product product = new Product("Blue Pen", 20);
product.remove_from_stock(5);
product.display_stock();
product.remove_from_stock(30);