static void Main(string[] args) { // Opgave 1 Console.WriteLine(" - Opgave 1"); BubbleGumDispenser bubbleGumDispenser = new BubbleGumDispenser(55); for (int i = 0; i < 8; i++) { BubbleGum bubbleGum = bubbleGumDispenser.Dispence(); if (bubbleGum != null) { Console.WriteLine("Kid-" + i + " got a " + bubbleGum.GetColor() + " colored bubblegum with " + bubbleGum.GetTaste() + " flavor"); } else { Console.WriteLine("Kid-" + i + " got nothing!"); } } // Opgave 2 Console.WriteLine("\n - Opgave 2"); BubbleGumDispenserStatic.FillDispencer(55); for (int i = 0; i < 8; i++) { BubbleGum bubbleGum = BubbleGumDispenserStatic.Dispence(); if (bubbleGum != null) { Console.WriteLine("Kid-" + i + " got a " + bubbleGum.GetColor() + " colored bubblegum with " + bubbleGum.GetTaste() + " flavor"); } else { Console.WriteLine("Kid-" + i + " got nothing!"); } } }
// Used to add bubblegums to the dicpencer and specify the amount in procent static private void AddBubbleGum(BubbleGum bubbleGum, float procent) { int loopAmount = (int)(Math.Ceiling((amount / 100.0f) * procent)); for (int i = 0; i < loopAmount; i++) { bubbleGums.Add(bubbleGum); } }
// Picks random bubblegum in the dispencer list and then remove- and return it static private BubbleGum DispenceMechanic() { if (amount >= 1) { int index = random.Next(0, amount); amount--; BubbleGum bubbleGum = bubbleGums[index]; bubbleGums.RemoveAt(index); return(bubbleGum); } else { return(null); } }