//Takes in a string and returns a can of that type if available. //If stock does not contain that type of can, this will return null public Can PrepareCan(string canChoice) { Can actualCan = null; switch (canChoice) { case "Cola": Can cola = new Cola(); if (ContainsCan(cola)) { actualCan = cola; } break; case "Orange Soda": Can orange = new OrangeSoda(); if (ContainsCan(orange)) { actualCan = orange; } break; case "Root Beer": Can rootbeer = new RootBeer(); if (ContainsCan(rootbeer)) { actualCan = rootbeer; } break; default: break; } return(actualCan); }
//Properties //Constructor public SodaMachine() { register = new List <Coin>(); inventory = new List <Can>(); if (register.Count < 100) { while (register.Count < 20) { Quarter quarter = new Quarter(); register.Add(quarter); } while (register.Count >= 20 && register.Count < 30) { Dime dime = new Dime(); register.Add(dime); } while (register.Count >= 30 && register.Count < 50) { Nickel nickel = new Nickel(); register.Add(nickel); } while (register.Count >= 50 && register.Count < 100) { Penny penny = new Penny(); register.Add(penny); } } if (inventory.Count < 50) { while (inventory.Count < 15) { Cola cola = new Cola(); inventory.Add(cola); } while (inventory.Count >= 15 && inventory.Count < 30) { OrangeSoda orangeSoda = new OrangeSoda(); inventory.Add(orangeSoda); } while (inventory.Count >= 30 && inventory.Count < 50) { RootBeer rootBeer = new RootBeer(); inventory.Add(rootBeer); } } }