private string ReadCommand(string command) { string[] tokens = command.Split(); var output = string.Empty; string[] args = tokens.Skip(1).ToArray(); switch (tokens[0]) { case "AddFood": output = restaurantController.AddFood(args[0], args[1], decimal.Parse(args[2])); break; case "AddDrink": output = restaurantController.AddDrink(args[0], args[1], int.Parse(args[2]), args[3]); break; case "AddTable": output = restaurantController.AddTable(args[0], int.Parse(args[1]), int.Parse(args[2])); break; case "ReserveTable": output = restaurantController.ReserveTable(int.Parse(args[0])); break; case "OrderFood": output = restaurantController.OrderFood(int.Parse(args[0]), args[1]); break; case "OrderDrink": output = restaurantController.OrderDrink(int.Parse(args[0]), args[1], args[2]); break; case "LeaveTable": output = restaurantController.LeaveTable(int.Parse(args[0])); break; case "GetFreeTablesInfo": output = restaurantController.GetFreeTablesInfo(); break; case "GetOccupiedTablesInfo": output = restaurantController.GetOccupiedTablesInfo(); break; } return(output); }
public void MoveCommand(string inputLine, RestaurantController rc) { string[] input = inputLine.Split(); string command = input[0]; switch (command) { case "AddFood": Console.WriteLine(rc.AddFood(input[1], input[2], decimal.Parse(input[3]))); break; case "AddDrink": Console.WriteLine(rc.AddDrink(input[1], input[2], int.Parse(input[3]), input[4])); break; case "AddTable": Console.WriteLine(rc.AddTable(input[1], int.Parse(input[2]), int.Parse(input[3]))); break; case "ReserveTable": Console.WriteLine(rc.ReserveTable(int.Parse(input[1]))); break; case "OrderFood": Console.WriteLine(rc.OrderFood(int.Parse(input[1]), input[2])); break; case "OrderDrink": Console.WriteLine(rc.OrderDrink(int.Parse(input[1]), input[2], input[3])); break; case "LeaveTable": Console.WriteLine(rc.LeaveTable(int.Parse(input[1]))); break; case "GetFreeTablesInfo": Console.WriteLine(rc.GetFreeTablesInfo()); break; case "GetOccupiedTablesInfo": Console.WriteLine(rc.GetOccupiedTablesInfo()); break; default: break; } }
public void Run() { string input = reader.Read(); while (input != "END") { string[] arguments = input.Split().ToArray(); string command = arguments[0]; string[] parameters = arguments.Skip(1).ToArray(); string result = string.Empty; try { switch (command) { case "AddFood": //{type} {name} {price} string foodType = parameters[0]; string foodName = parameters[1]; decimal foodPrice = decimal.Parse(parameters[2]); result = restaurant.AddFood(foodType, foodName, foodPrice); writer.Write(result); break; case "AddDrink": //{type} {name} {servingSize} {brand} string drinkType = parameters[0]; string drinkName = parameters[1]; int drinkServingSize = int.Parse(parameters[2]); string drinkBrand = parameters[3]; result = restaurant.AddDrink(drinkType, drinkName, drinkServingSize, drinkBrand); writer.Write(result); break; case "AddTable": //{type} {tableNumber} {capacity} string tableType = parameters[0]; int tableNumber = int.Parse(parameters[1]); int tableCapacity = int.Parse(parameters[2]); result = restaurant.AddTable(tableType, tableNumber, tableCapacity); writer.Write(result); break; case "ReserveTable": //{numberOfPeople} int numberOfPeople = int.Parse(parameters[0]); result = restaurant.ReserveTable(numberOfPeople); writer.Write(result); break; case "OrderFood": // {tableNumber} {foodName} int tableToOrder = int.Parse(parameters[0]); string foodToOrder = parameters[1]; result = restaurant.OrderFood(tableToOrder, foodToOrder); writer.Write(result); break; case "OrderDrink": // {tableNumber} {drinkName} {drinkBrand} tableToOrder = int.Parse(parameters[0]); string drinkToOrder = parameters[1]; drinkBrand = parameters[2]; result = restaurant.OrderDrink(tableToOrder, drinkToOrder, drinkBrand); writer.Write(result); break; case "LeaveTable": // {tableNumber} int tableToLeave = int.Parse(parameters[0]); result = restaurant.LeaveTable(tableToLeave); writer.Write(result); break; case "GetFreeTablesInfo": result = restaurant.GetFreeTablesInfo(); if (result.Length > 0) { writer.Write(result); } break; case "GetOccupiedTablesInfo": result = restaurant.GetOccupiedTablesInfo(); if (result.Length > 0) { writer.Write(result); } break; } } catch (ArgumentException ae) { writer.Write(ae.Message); } catch (Exception e) { writer.Write(e.Message); } input = reader.Read(); } string sumary = restaurant.GetSummary(); writer.Write(sumary); }
private void ReadCommands(string input, StringBuilder result) { string[] inputLine = input.Split(); string command = inputLine[0]; switch (command) { case "AddFood": { string type = inputLine[1]; string name = inputLine[2]; decimal price = decimal.Parse(inputLine[3]); result.AppendLine(controller.AddFood(type, name, price)); } break; case "AddDrink": { string type = inputLine[1]; string name = inputLine[2]; int servingSize = int.Parse(inputLine[3]); string brand = inputLine[4]; result.AppendLine(controller.AddDrink(type, name, servingSize, brand)); } break; case "AddTable": { string type = inputLine[1]; int tableNumber = int.Parse(inputLine[2]); int capacity = int.Parse(inputLine[3]); result.AppendLine(controller.AddTable(type, tableNumber, capacity)); } break; case "ReserveTable": { int numberOfPeople = int.Parse(inputLine[1]); result.AppendLine(controller.ReserveTable(numberOfPeople)); } break; case "OrderFood": { int tableNumber = int.Parse(inputLine[1]); string foodName = inputLine[2]; result.AppendLine(controller.OrderFood(tableNumber, foodName)); } break; case "OrderDrink": { int tableNumber = int.Parse(inputLine[1]); string drinkName = inputLine[2]; string drinkBrand = inputLine[3]; result.AppendLine(controller.OrderDrink(tableNumber, drinkName, drinkBrand)); } break; case "LeaveTable": { int tableNumber = int.Parse(inputLine[1]); result.AppendLine(controller.LeaveTable(tableNumber)); } break; case "GetFreeTablesInfo": { result.AppendLine(this.controller.GetFreeTablesInfo()); } break; case "GetOccupiedTablesInfo": { result.AppendLine(this.controller.GetOccupiedTablesInfo()); } break; default: break; } }
public void Run() { string input = Console.ReadLine(); while (input != "END") { List <string> args = input.Split().ToList(); string command = args[0]; args.RemoveAt(0); string result = string.Empty; try { switch (command) { case "AddFood": string type = args[0]; string name = args[1]; decimal price = decimal.Parse(args[2]); result = restaurantController.AddFood(type, name, price); break; case "AddDrink": int servingSize = int.Parse(args[2]); string brand = args[3]; result = restaurantController.AddDrink(args[0], args[1], servingSize, brand); break; case "AddTable": int tableNumber = int.Parse(args[1]); int capacity = int.Parse(args[2]); result = restaurantController.AddTable(args[0], tableNumber, capacity); break; case "ReserveTable": int numberOfPeople = int.Parse(args[0]); result = restaurantController.ReserveTable(numberOfPeople); break; case "OrderFood": int tn = int.Parse(args[0]); string foodName = args[1]; result = restaurantController.OrderFood(tn, foodName); break; case "OrderDrink": int tn2 = int.Parse(args[0]); string drinkName = args[1]; string drinkBrand = args[2]; result = restaurantController.OrderDrink(tn2, drinkName, drinkBrand); break; case "LeaveTable": int tn3 = int.Parse(args[0]); result = restaurantController.LeaveTable(tn3); break; case "GetFreeTablesInfo": result = restaurantController.GetFreeTablesInfo(); break; case "GetOccupiedTablesInfo": result = restaurantController.GetOccupiedTablesInfo(); break; default: throw new ArgumentException($"{command} is an invalid command!"); } } catch (ArgumentException ae) { Console.Write(ae.Message); } Console.WriteLine(result); input = Console.ReadLine(); if (input == "END") { Console.WriteLine(restaurantController.GetSummary()); } } }
public void Run() { string input = Console.ReadLine(); while (input != "END") { string[] inputArgs = input.Split(); string command = inputArgs[0]; string[] args = inputArgs.Skip(1).ToArray(); string result = string.Empty; try { switch (command) { case "AddFood": string type = args[0]; string name = args[1]; decimal price = decimal.Parse(args[2]); result = restaurantController.AddFood(type, name, price); break; case "AddDrink": type = args[0]; name = args[1]; var servingSize = int.Parse(args[2]); var brand = args[3]; result = restaurantController.AddDrink(type, name, servingSize, brand); break; case "AddTable": type = args[0]; int tableNumber = int.Parse(args[1]); int capacity = int.Parse(args[2]); result = restaurantController.AddTable(type, tableNumber, capacity); break; case "ReserveTable": int numberOfPeople = int.Parse(args[0]); result = restaurantController.ReserveTable(numberOfPeople); break; case "OrderFood": tableNumber = int.Parse(args[0]); string foodName = args[1]; result = restaurantController.OrderFood(tableNumber, foodName); break; case "OrderDrink": tableNumber = int.Parse(args[0]); string drinkName = args[1]; string drinkBrand = args[2]; result = restaurantController.OrderDrink(tableNumber, drinkName, drinkBrand); break; case "LeaveTable": tableNumber = int.Parse(args[0]); result = restaurantController.LeaveTable(tableNumber); break; case "GetFreeTablesInfo": result = restaurantController.GetFreeTablesInfo(); break; case "GetOccupiedTablesInfo": result = restaurantController.GetOccupiedTablesInfo(); break; } Console.WriteLine(result); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } input = Console.ReadLine(); } Console.WriteLine(this.restaurantController.GetSummary()); }