diff --git a/CoffeeVendingMachines/CoinDepot.cs b/CoffeeVendingMachines/CoinDepot.cs index 9db21fe..dbd6fd2 100644 --- a/CoffeeVendingMachines/CoinDepot.cs +++ b/CoffeeVendingMachines/CoinDepot.cs @@ -10,4 +10,36 @@ public class CoinDepot Coin = coin; Count = count; } + + public CoinDepot(CoinDepot coinDepot) + { + Coin = coinDepot.Coin; + Count = coinDepot.Count; + } + + public void Add() + { + Count++; + } + + public void Clear() + { + Count = 0; + } + + public override string ToString() + { + return $"{Coin}: {Count}"; + } + + public bool Withdraw() + { + if (Count > 0) + { + Count--; + return true; + } + + return false; + } } diff --git a/CoffeeVendingMachines/Model.cs b/CoffeeVendingMachines/Model.cs index dab2854..7119c36 100644 --- a/CoffeeVendingMachines/Model.cs +++ b/CoffeeVendingMachines/Model.cs @@ -1,14 +1,11 @@ namespace CoffeeVendingMachines; -public class Model +public enum CoinType { - public enum CoinType - { - Cent05, - Cent10, - Cent20, - Cent50, - Euro01, - Euro02 - } -} + Cent05, + Cent10, + Cent20, + Cent50, + Euro01, + Euro02 +} \ No newline at end of file diff --git a/CoffeeVendingMachines/Product.cs b/CoffeeVendingMachines/Product.cs index e3a0a12..c3dbf64 100644 --- a/CoffeeVendingMachines/Product.cs +++ b/CoffeeVendingMachines/Product.cs @@ -2,5 +2,35 @@ public class Product { + public const int FallbackPrice = 50; + private readonly int _price; + private int _stock; + public bool InStock => _stock > 0; + public string Name { get; } + 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; + } + + public bool AddSale() + { + if (InStock) + { + NumberSold++; + _stock--; + return true; + } + + return false; + } + + public override string ToString() + { + return $"{Name} € {Price} [{_stock} in stock | {NumberSold} sold]"; + } }