From 92421e0be98bd8581dea5a111ed6b40b0534c813 Mon Sep 17 00:00:00 2001 From: MarcUs7i <96580944+MarcUs7i@users.noreply.github.com> Date: Mon, 18 Nov 2024 08:58:06 +0100 Subject: [PATCH] Finished CoffeeVendingMachine.cs Cancel class --- CoffeeVendingMachines/CoffeeVendingMachine.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/CoffeeVendingMachines/CoffeeVendingMachine.cs b/CoffeeVendingMachines/CoffeeVendingMachine.cs index 7b88ded..aeabf38 100644 --- a/CoffeeVendingMachines/CoffeeVendingMachine.cs +++ b/CoffeeVendingMachines/CoffeeVendingMachine.cs @@ -45,8 +45,27 @@ public class CoffeeVendingMachine public CoinDepot[] Cancel() { - //TODO - return []; + int count = 0; + foreach (var inputCoin in _currentInputCoins) + { + if (inputCoin.Count > 0) + { + count++; + } + } + CoinDepot[] newInputCoins = new CoinDepot[count]; + + int j = 0; + for (int i = 0; i < _currentInputCoins.Length; i++) + { + if (_currentInputCoins[i].Count > 0) + { + newInputCoins[j] = new CoinDepot(_currentInputCoins[i]); + j++; + } + } + + return newInputCoins; } ///