private void DisplayCoffeeType() { coffeeType = (CoffeeType)Session["CoffeeType"]; if (Session["CoffeeType"] != null) { if (coffeeType.Coffee == "Espresso") { ddlCoffeeTypes.SelectedIndex = 1; } else if (coffeeType.Coffee == "Mocha") { ddlCoffeeTypes.SelectedIndex = 2; } else if (coffeeType.Coffee == "Latte") { ddlCoffeeTypes.SelectedIndex = 3; } else { ddlCoffeeTypes.SelectedIndex = 0; } } else { return; } Session["CoffeeType"] = null; }
public void Test(CoffeeType coffeeType, SugarLevel sugarLevel, Size size) { var money = coffeeType.Price(); CoffeeMachine.SelectCoffee(coffeeType); CoffeeMachine.InsertMoney(money); CoffeeMachine.WorkStatus.Should().Be(WorkStatus.Customization); CoffeeMachine.SelectSugarLevel(sugarLevel); CoffeeMachine.SelectSize(size); CoffeeMachine.WorkStatus.Should().Be(WorkStatus.ReadyForMakingCoffee); CoffeeMachine.Run(); CoffeeMachine.WorkStatus.Should().Be(WorkStatus.TakeYourCoffee); CoffeeMachine.GetChange().Should().Be(0); var coffee = CoffeeMachine.EjectCup(); coffee.Should().BeEquivalentTo(new Coffee(coffeeType, sugarLevel, size)); CoffeeMachine.WorkStatus.Should().Be(WorkStatus.InsertMoneyOrSelectCoffee); CoffeeMachine.Size.Should().Be(Size.Unknown); CoffeeMachine.SugarLevel.Should().Be(SugarLevel.Unknown); CoffeeMachine.CoffeeType.Should().Be(CoffeeType.Unknown); }
private void SetDefaultValues() { _type = CoffeeType.Espresso; _size = CoffeeSize.Small; _sweetness = CoffeeSweetness.OneSpoon; _addons.Clear(); }
public void CorrectWorkTest() { const int money = 500; const CoffeeType type = CoffeeType.Cappucchino; const SugarLevel sugarLevel = SugarLevel.Medium; const Size size = Size.Large; CoffeeMachine.SelectCoffee(type); CoffeeMachine.InsertMoney(money); CoffeeMachine.WorkStatus.Should().Be(WorkStatus.Customization); CoffeeMachine.SelectSugarLevel(sugarLevel); CoffeeMachine.SelectSize(size); CoffeeMachine.WorkStatus.Should().Be(WorkStatus.ReadyForMakingCoffee); CoffeeMachine.Run(); CoffeeMachine.WorkStatus.Should().Be(WorkStatus.TakeYourCoffee); CoffeeMachine.GetChange().Should().Be(money - type.Price()); var coffee = CoffeeMachine.EjectCup(); coffee.Should().BeEquivalentTo(new Coffee(type, sugarLevel, size)); CoffeeMachine.WorkStatus.Should().Be(WorkStatus.InsertMoneyOrSelectCoffee); CoffeeMachine.Size.Should().Be(Size.Unknown); CoffeeMachine.SugarLevel.Should().Be(SugarLevel.Unknown); CoffeeMachine.CoffeeType.Should().Be(CoffeeType.Unknown); }
async void OnCoffeeList_ItemTapped(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem != null) { CoffeeType coffeeType = ((ListView)sender).SelectedItem as CoffeeType; await Navigation.PushAsync(new CoffeeTypePage(coffeeType)); } }
private void CheckPriceAndPurchase(CoffeeType coffeeType, CoffeePrice price) { if (this.InsertedCoins >= (int)price) { this.CoffeesSold.Add(coffeeType); this.InsertedCoins = 0; } }
public override void Run() { if (WorkStatus != WorkStatus.ReadyForMakingCoffee) { throw new CoffeeMachineException("You can't start making coffee. First, select Coffee Type, Size and Sugar level"); } Balance -= CoffeeType.Price(); WorkStatus = WorkStatus.TakeYourCoffee; }
public override void SelectCoffee(CoffeeType coffeeType) { if (WorkStatus == WorkStatus.TakeYourCoffee) { throw new CoffeeMachineException("You can't select coffee type. First, take a cup from the coffee machine"); } CoffeeType = coffeeType; WorkStatus = Balance >= CoffeeType.Price() ? WorkStatus.Customization : WorkStatus.InsertMoneyOrSelectCoffee; }
public override void SelectCoffee(CoffeeType coffeeType) { if (coffeeType == CoffeeType.Unknown) { throw new CoffeeMachineException("You must select correct coffee type!"); } CoffeeType = coffeeType; WorkStatus = Balance >= CoffeeType.Price() ? WorkStatus.Customization : WorkStatus.InsertMoneyOrSelectCoffee; }
/// <summary> /// Takes in Coffee Choice and sets to that. Then progresses to asking milk /// </summary> /// <param name="CurrentChoice"></param> private void CoffeeSelection(CoffeeType CurrentChoice) { if (CurrentChoice == CoffeeType.None) { return; } myCoffeeChoice = CurrentChoice; currentOrderStatus = OrderStatus.AskMilk; }
public Coffee(int discount, CoffeeType coffeeType) { this.coffeeType = coffeeType; this.discount = discount; if (discount > 5) { Console.WriteLine("Discount cannot be more than 5"); throw new Exception("Discount cannot be more than 5"); } }
public void TestSugarLevelAfterGettingChange() { const CoffeeType coffeeType = CoffeeType.Americano; CoffeeMachine.SelectCoffee(coffeeType); CoffeeMachine.InsertMoney(coffeeType.Price()); CoffeeMachine.SelectSize(Size.Normal); CoffeeMachine.SelectSugarLevel(SugarLevel.Medium); CoffeeMachine.GetChange(); CoffeeMachine.SugarLevel.Should().Be(SugarLevel.Unknown); }
public void BuyCoffee(string size, string type) { CoffeeType coffeeType = (CoffeeType)Enum.Parse(typeof(CoffeeType), type); CoffeePrice coffeePrice = (CoffeePrice)Enum.Parse(typeof(CoffeePrice), size); if (totalInsertedCoins >= (int)coffeePrice) { coffeesSold.Add(coffeeType); totalInsertedCoins = 0; } }
public void BuyCoffee(string price, string type) { CoffeeType coffeeType = (CoffeeType)Enum.Parse(typeof(CoffeeType), type); CoffeePrice coffeePrice = (CoffeePrice)Enum.Parse(typeof(CoffeePrice), price); if (this.Coins >= (int)coffeePrice) { this.CoffeesSold.Add(coffeeType); this.Coins = 0; } }
public void BuyCoffee(string size, string type) { CoffeePrice coffeePrice = (CoffeePrice)Enum.Parse(typeof(CoffeePrice), size); int price = (int)coffeePrice; CoffeeType coffeeType = (CoffeeType)Enum.Parse(typeof(CoffeeType), type); if (this.totalMoney >= price) { this.CoffeesSold.Add(coffeeType); } }
public void BuyCoffee(string size, string type) { CoffeeType coffeeType = (CoffeeType)Enum.Parse(typeof(CoffeeType), type); CoffeePrice coffeePrice = (CoffeePrice)Enum.Parse(typeof(CoffeePrice), size); if (coins >= (int)coffeePrice) { this.coffeeSold.Add(coffeeType); this.coins = 0; } }
public void BuyCoffee(string size, string type) { CoffeeType coffeeType = (CoffeeType)Enum.Parse(typeof(CoffeeType), type); CoffeePrice price = (CoffeePrice)Enum.Parse(typeof(CoffeePrice), size); if (this.coinsValue >= (int)price) { this.CoffeesSold.Add(coffeeType); this.coinsValue -= (int)price; } }
public void SetCoffeeType(CoffeeType value) { try { coffeeType = value; } catch (MyCustomException exception) { throw new MyCustomException("Couldnt set coffee type!"); } }
public void BuyCoffee(string size, string type) { int prize = (int)Enum.Parse(typeof(CoffeePrice), size); if (this.coins.Sum(c => (int)c) >= prize) { CoffeeType cofType = (CoffeeType)Enum.Parse(typeof(CoffeeType), type); this.coffeesSold.Add(cofType); this.coins.Clear(); } }
public override void InsertMoney(int moneyAmount) { if (moneyAmount < 0) { throw new CoffeeMachineException("Amount must be a positive number"); } Balance += moneyAmount; WorkStatus = CoffeeType != CoffeeType.Unknown && Balance >= CoffeeType.Price() ? WorkStatus.Customization : WorkStatus.InsertMoneyOrSelectCoffee; }
static void Main(string[] args) { Console.Write("Enter coffee number: "); int coffeeNumber = int.Parse(Console.ReadLine()); CoffeeType coffeeType = (CoffeeType)coffeeNumber; Coffee coffee = CoffeeFactory.GetCoffee(coffeeType); coffee.Print(); Console.ReadKey(true); }
public Coffee FindCoffeeFromShopsSelectionFor(Order order) { Coffee c; if (order != null && Array.IndexOf(CoffeeType.CoffeeTypesByName(), order.drink) > -1 && !String.IsNullOrEmpty(order.size)) { c = coffeeSelection.FirstOrDefault(d => d.GetSize() == order.size && d.GetName() == order.drink) ?? new NullCoffee(); return(c); } return(new NullCoffee()); }
public virtual void ServeCoffee(CoffeeType type, ISmartCoffeeCup cup) { try { ServeCoffeeInternal(type, cup); } catch (Exception ex) { Audit("Ërror while serving coffee"); throw; } }
public void BuyCoffee(string size, string type) { CoffeePrice coffeePrice = (CoffeePrice)Enum.Parse(typeof(CoffeePrice), size); var intCoffePrice = (int)coffeePrice; CoffeeType coffeeType = (CoffeeType)Enum.Parse(typeof(CoffeeType), type); if (allMoney >= intCoffePrice) { coffeesSold.Add(coffeeType); allMoney = 0; } }
public override void Run() { if (WorkStatus == WorkStatus.TakeYourCoffee) { throw new CoffeeMachineException("You can't start making coffee. First, take a cup from the coffee machine"); } if (WorkStatus == WorkStatus.InsertMoneyOrSelectCoffee) { throw new CoffeeMachineException("You can't start making coffee. First, select Coffee Type, Size and Sugar level"); } Balance -= CoffeeType.Price(); WorkStatus = WorkStatus.TakeYourCoffee; }
public void TestInsertTenCoins() { const CoffeeType coffeeType = CoffeeType.Cappucchino; CoffeeMachine.SelectCoffee(coffeeType); for (var i = 0; i < 10; i++) { CoffeeMachine.InsertMoney(1); } CoffeeMachine.Balance.Should().BeLessThan(coffeeType.Price()); CoffeeMachine.WorkStatus.Should().Be(WorkStatus.InsertMoneyOrSelectCoffee); }
public void PrintCaffee() { CoffeeType order = CaffeeType(); foreach (var item in Ingredients) { Console.WriteLine(item); } Console.WriteLine("-----------------------------"); Console.WriteLine($"Your order is ready : {order} :)"); Console.WriteLine(); }
public void BuyCoffee(string size, string type) { CoffeeType currentType = Enum.Parse <CoffeeType>(type); CoffeePrice price = Enum.Parse <CoffeePrice>(size); int currentBudget = 0; this.coins.ForEach(x => currentBudget += (int)x); if (currentBudget >= (int)price) { this.CoffeesSold.Add(currentType); this.coins.Clear(); } }
public void StatusAfterGetChange() { const int money = 150; const CoffeeType type = CoffeeType.Latte; CoffeeMachine.SelectCoffee(type); CoffeeMachine.InsertMoney(money); CoffeeMachine.SelectSize(Size.Normal); CoffeeMachine.SelectSugarLevel(SugarLevel.Low); CoffeeMachine.Run(); CoffeeMachine.GetChange(); CoffeeMachine.WorkStatus.Should().Be(WorkStatus.TakeYourCoffee); }
public override void SelectCoffee(CoffeeType coffeeType) { if (WorkStatus == WorkStatus.TakeYourCoffee) { throw new CoffeeMachineException("You can't select coffee type. First, take a cup from the coffee machine"); } if (coffeeType == CoffeeType.Unknown) { throw new CoffeeMachineException("You must select correct coffee type!"); } CoffeeType = coffeeType; WorkStatus = WorkStatus.Customization; }
public static Coffee GetCoffee(CoffeeType coffeeType) { switch (coffeeType) { case CoffeeType.Regular: return new Coffee(0, 150); case CoffeeType.Double: return new Coffee(0, 200); case CoffeeType.Cappuccino: return new Coffee(100, 100); case CoffeeType.Macchiato: return new Coffee(200, 100); default: throw new ArgumentException(); } }
// Parameter can be string (e.g. from configuration file) // Also the method can be static but we won't be able to extend the class public Coffee GetCoffee(CoffeeType coffeeType) { // Can also be implemented using dictionary switch (coffeeType) { case CoffeeType.Regular: // Can be subtype of Coffee return new Coffee(0, 150); case CoffeeType.Double: return new Coffee(0, 200); case CoffeeType.Cappuccino: return new Coffee(100, 100); case CoffeeType.Macchiato: return new Coffee(200, 100); default: throw new ArgumentException(); } }