ex-oop-05-coffe-vending-mac.../CoffeeVendingMachines/Product.cs
MarcUs7i bc7f2da775 Initialized the CoffeeVendingMachine.cs class
Rewrote from get/set like in the README
2024-11-16 19:48:16 +01:00

37 lines
815 B
C#

namespace CoffeeVendingMachines;
public class Product
{
public const int FallbackPrice = 50;
private readonly int _price;
private int _stock;
public readonly bool InStock;
public readonly string Name;
public int NumberSold { get; private set; }
public int Price { get; private init; }
public Product (string name, int price = FallbackPrice, int stock = 0)
{
Name = name;
_price = price;
_stock = stock;
InStock = _stock > 0;
}
public bool AddSale()
{
if (InStock)
{
NumberSold++;
_stock--;
return true;
}
return false;
}
public override string ToString()
{
return $"{Name} € {Price} [{_stock} in stock | {NumberSold} sold]";
}
}