You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
933 B
38 lines
933 B
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace State_VendingMachineExample
|
|
{
|
|
internal class DispenseChangeState : VMState
|
|
{
|
|
public DispenseChangeState(VendingMachine context)
|
|
{
|
|
vendingMachine = context;
|
|
}
|
|
|
|
public override void AddMoney(decimal money)
|
|
{
|
|
throw new ApplicationException();
|
|
}
|
|
|
|
public override void ReturnChange(decimal money)
|
|
{
|
|
// Return charge here
|
|
if (vendingMachine.Money > 0)
|
|
{
|
|
Console.WriteLine($"Return charge ${money}");
|
|
vendingMachine.Money -= money;
|
|
}
|
|
|
|
vendingMachine.State = vendingMachine.ReadyState;
|
|
}
|
|
|
|
public override void SelectItem(int itemId)
|
|
{
|
|
throw new ApplicationException();
|
|
}
|
|
}
|
|
}
|
|
|