public override void SelectDocument(CopyMachine copyMachine, int document) { if (document < 0 || copyMachine.SelectedDevice.DocumentCount <= document) { throw new IndexOutOfRangeException("Invalid document"); } copyMachine.SelectedDocument = document; }
public override int TakeChange(CopyMachine copyMachine) { Console.WriteLine($"Take the change of {copyMachine.Coins} coins"); var change = copyMachine.Coins; copyMachine.Coins = 0; copyMachine.State = new CompleteState(); return(change); }
public override void AddCash(CopyMachine copyMachine) { ConsolePrintHelper.WriteLineLabel("Добро пожаловать!"); ConsolePrintHelper.WriteLabel("Цена одной страницы : "); ConsolePrintHelper.WriteLineValue(copyMachine.CostOfPage.ToString()); ConsolePrintHelper.WriteLineLabel("Внесите сумму:"); copyMachine.Cash = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); copyMachine.State = new ChooseDeviceState(); copyMachine.State.ChooseDevice(copyMachine); }
public override void Print(CopyMachine copyMachine) { if (copyMachine.MoneyCount < copyMachine.PricePerDocument) { throw new Exception("Not enough money"); } copyMachine.MoneyCount -= copyMachine.PricePerDocument; Console.Write(copyMachine.SelectedDevice.GetDocument(copyMachine.SelectedDocument)); copyMachine.State = new SelectedDeviceState(); }
public override void SelectDocument(CopyMachine copyMachine, int docNumber) { if (copyMachine.Coins > 0) { Console.WriteLine($"Selected document number {docNumber}"); copyMachine.State = new PrintState(); } else { Console.WriteLine("Sorry, deposit is empty for printing documents"); copyMachine.State = new CompleteState(); } }
static void Main(string[] args) { var copyMachine = new CopyMachine(); copyMachine.DepositCoins(1); copyMachine.SelectStorageMedia(StorageMedia.UsbFlashDrive); copyMachine.SelectDocument(1); copyMachine.Print(); copyMachine.SelectDocument(3); copyMachine.Print(); copyMachine.TakeChange(); copyMachine.Complete(); }
public override void ChooseDocument(CopyMachine copyMachine) { ConsolePrintHelper.WriteLineLabel("Выберите документ:"); foreach (var document in copyMachine.Device.Documents) { ConsolePrintHelper.WriteLabel($"{nameof(document.Id)} : "); ConsolePrintHelper.WriteValue(document.Id.ToString()); ConsolePrintHelper.WriteLabel("; "); ConsolePrintHelper.WriteLabel($"{nameof(document.Name)} : "); ConsolePrintHelper.WriteLineValue(document.Name); } var documentId = int.Parse(Console.ReadLine()); copyMachine.Document = copyMachine.Device.Documents.First(i => i.Id == documentId); copyMachine.State = new PrintDocumentState(); copyMachine.State.PrintDocument(copyMachine); }
public override void ChooseDevice(CopyMachine copyMachine) { ConsolePrintHelper.WriteLineLabel("Выберите устройство:"); foreach (var device in Program.Devices) { ConsolePrintHelper.WriteLabel($"{nameof(device.Id)} : "); ConsolePrintHelper.WriteValue(device.Id.ToString()); ConsolePrintHelper.WriteLabel("; "); ConsolePrintHelper.WriteLabel($"{nameof(device.Name)} : "); ConsolePrintHelper.WriteLineValue(device.Name); } var deviceId = int.Parse(Console.ReadLine()); copyMachine.Device = Program.Devices.First(i => i.Id == deviceId); copyMachine.State = new ChooseDocumentState(); copyMachine.State.ChooseDocument(copyMachine); }
public override void PrintDocument(CopyMachine copyMachine) { var cost = copyMachine.Document.AmountOfPages * copyMachine.CostOfPage; if (copyMachine.Cash - cost < 0) { copyMachine.Error = "Внесенных средств недостаточно"; copyMachine.State = new ErrorState(); copyMachine.State.PrintError(copyMachine); return; } copyMachine.Cash -= cost; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"Печать документа: \"{copyMachine.Document.Name}\""); Console.ResetColor(); copyMachine.State = new AskTheQuestionState(); copyMachine.State.AskTheQuestion(copyMachine); }
public override void AskTheQuestion(CopyMachine copyMachine) { ConsolePrintHelper.WriteLineLabel("Хотите распечатать еще документ?"); ConsolePrintHelper.WriteLabel("1 : "); ConsolePrintHelper.WriteLineValue("Да"); ConsolePrintHelper.WriteLabel("2 : "); ConsolePrintHelper.WriteLineValue("Нет"); var result = int.Parse(Console.ReadLine()); if (result == 1) { copyMachine.State = new ChooseDocumentState(); copyMachine.State.ChooseDocument(copyMachine); return; } copyMachine.State = new ReturnDeliveryState(); copyMachine.State.ReturnDelivery(copyMachine); }
public virtual void AddCash(CopyMachine copyMachine) { ThrowException(); }
public virtual void Cancel(CopyMachine copyMachine) { ThrowException(); }
public virtual void PrintError(CopyMachine copyMachine) { ThrowException(); }
public virtual void ReturnDelivery(CopyMachine copyMachine) { ThrowException(); }
public virtual void SayGoodbye(CopyMachine copyMachine) { ThrowException(); }
public virtual void PrintDocument(CopyMachine copyMachine) { ThrowException(); }
public virtual void AskTheQuestion(CopyMachine copyMachine) { ThrowException(); }
public override void Print(CopyMachine copyMachine) { throw new Exception("Device not selected"); }
public virtual void SelectDocument(CopyMachine copyMachine, int docNumber) { throw new Exception("It's impossible to select document now"); }
public virtual void DepositCoins(CopyMachine copyMachine, int coins) { throw new Exception("It's impossible to deposit coins now"); }
public virtual void Print(CopyMachine copyMachine) { throw new Exception("It's impossible to print documents now"); }
public virtual int TakeChange(CopyMachine copyMachine) { throw new Exception("It's impossible to take change now"); }
public override void DepositCoins(CopyMachine copyMachine, int coins) { Console.WriteLine($"{coins} coins were deposited"); copyMachine.Coins += coins; }
public override void SelectStorageMedia(CopyMachine copyMachine, StorageMedia storageMedia) { throw new Exception("You haven't deposited any coins yet"); }
public override void DepositCoins(CopyMachine copyMachine, int coins) { copyMachine.Coins += coins; Console.WriteLine($"{coins} coins were deposited"); copyMachine.State = new SelectStorageMediaState(); }
public virtual void Complete(CopyMachine copyMachine) { Console.WriteLine("Thank you for using the copy machine :)"); copyMachine.State = new InitState(); }
public override void SelectDocument(CopyMachine copyMachine, int document) { throw new Exception("Device not selected"); }
public virtual void ChooseDevice(CopyMachine copyMachine) { ThrowException(); }
public virtual void ChooseDocument(CopyMachine copyMachine) { ThrowException(); }
public virtual void SelectStorageMedia(CopyMachine copyMachine, StorageMedia storageMedia) { throw new Exception("It's impossible to select storage media now"); }