Implemented 2 classes

This commit is contained in:
MarcUs7i 2024-11-16 19:20:52 +01:00
parent 82669405e4
commit c81ca36d28
3 changed files with 70 additions and 11 deletions

View file

@ -10,4 +10,36 @@ public class CoinDepot
Coin = coin; Coin = coin;
Count = count; 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;
}
} }

View file

@ -1,14 +1,11 @@
namespace CoffeeVendingMachines; namespace CoffeeVendingMachines;
public class Model public enum CoinType
{ {
public enum CoinType Cent05,
{ Cent10,
Cent05, Cent20,
Cent10, Cent50,
Cent20, Euro01,
Cent50, Euro02
Euro01,
Euro02
}
} }

View file

@ -2,5 +2,35 @@
public class Product 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]";
}
} }