public Purchase InputPurchase() { { Console.WriteLine(INPUT_TYPE); string type = inputer.InputStrings(); Console.WriteLine(INPUT_NAME); string name = inputer.InputStrings(); Console.WriteLine(INPUT_QUANTITY); int quantity = inputer.InputQuantity(); if (quantity.GetType() != typeof(Int32)) { throw new FormatException(); } if (quantity < 0) { throw new NegativeQuantityException(NEGATIVE_QUANTITY_EXCEPTION); } Console.WriteLine(INPUT_PRICE); decimal price = inputer.InputPrice(); if (price.GetType() != typeof(Decimal)) { throw new FormatException(); } if (price < 0) { throw new NegativePriceException(NEGATIVE_PRICE_EXCEPTION); } Purchase purchase = new Purchase(type, name, quantity, price); return(purchase); } }
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(); } }