public void OutputPurchase(PurchaseBuilder purchaseBuilder) { foreach (Purchase purchase in purchaseBuilder.ArrayPurchaseBuild()) { Console.WriteLine(purchase.OutputPurchase()); } }
public string BuildCommands(string inputedCommand, List <Purchase> purchaseArray) { PurchaseBuilder purchaseBuilder = new PurchaseBuilder(); Commands commands = new Commands(); string result = String.Empty; if (inputedCommand.Equals(COUNT_TYPES)) { Console.Write(QUANTITY_OF_TYPES); result = Convert.ToString(commands.CountTypes(purchaseArray)); } else if (inputedCommand.Equals(COUNT_ALL)) { Console.Write(QUANTITY); result = Convert.ToString(commands.CountQuantity(purchaseArray)); } else if (inputedCommand.Equals(AVERAGE_PRICE)) { Console.Write(AVERAGE_PRICE_ALL); result = Convert.ToString(commands.CountPrice(purchaseArray)); } else if (inputedCommand.Contains(AVERAGE_PRICE)) { string averagePriceType = inputedCommand.Remove(0, 14); string averagePrice = string.Concat(AVERAGE_PRICE, SPACE, averagePriceType); string resultAverageType = string.Concat(AVERAGE_PRICE_TYPE, averagePriceType, SPACE, IS); if (inputedCommand.Equals(averagePrice)) { Console.Write(resultAverageType); result = Convert.ToString(commands.AverageCountPrice(averagePriceType, purchaseArray)); } } else { throw new NotExistentCommandException(COMMAND_NOT_EXIST); } return(result); }
static void Main(string[] args) { const string CONTINUE_OR_EXIT = "\n1)To stop the program enter 'exit' and ENTER." + "\nTo create new product list enter 'new product list'."; const string CONTINUE_COMMANDS = "\n2)To enter new commands press 'new command'." + "\nTo create new product list enter 'new product list'."; string nextActivity = String.Empty; bool checkStop = true; while (checkStop == true) { try { PurchaseBuilder purchaseBuilder = new PurchaseBuilder(); Outputer outputer = new Outputer(); purchaseBuilder.BuildPurchase(); Inputer inputer = new Inputer(); bool mark = true; while (mark) { try { outputer.OutputPurchase(purchaseBuilder); outputer.OutputCommands(); string inputedCommand = inputer.InputStrings(); CommandsBuilder commandsBuilder = new CommandsBuilder(); string commandResult = commandsBuilder.BuildCommands(inputedCommand, purchaseBuilder.ArrayPurchaseBuild()); Console.Write(commandResult); Console.WriteLine(CONTINUE_COMMANDS); Console.WriteLine(CONTINUE_OR_EXIT); nextActivity = Console.ReadLine(); if (nextActivity.Equals("new command")) { continue; } else { break; } } catch (NotExistentTypeAverageTypeCommandException typeMessage) { Console.WriteLine(typeMessage.Message); continue; } catch (NotExistentCommandException commandMessage) { Console.WriteLine(commandMessage.Message); continue; } } } catch (NegativeQuantityException quantityMessage) { Console.WriteLine(quantityMessage.Message); continue; } catch (NegativePriceException priceMessage) { Console.WriteLine(priceMessage.Message); continue; } if (nextActivity.Equals("exit")) { break; } if (nextActivity.Equals("new product list")) { continue; } checkStop = false; Console.ReadKey(); } }