internal void Run() { do { ui.Clear(); ui.Print("Welcome"); ui.ShowMeny(); var input = Util.AskForKey(""); if (menyOptions.ContainsKey(input)) { menyOptions[input].Invoke(); } } while (true); }
public void TotalParkedVehicles(int vItem, string vType) { if (vItem > 0) { ui.Print($"In Garage has: {vItem}, and {vType}"); } }
public void CountParkedVehicles(int vehicleItem, string vehicleType) { if (vehicleItem > 0) { ui.Print($"{vehicleItem} {vehicleType} in the garage"); } }
private static void UserAction() { //Tar ett värde från användaren //Testar olika case tex användaren skriver in "1" då kör vi AddEmployee(). //Om vi inte träffar något case körs default koden switch (Console.ReadLine()) { case "1": AddEmployee(); break; case "2": PrintEmployee(); break; case "3": //Avslutar programmet Environment.Exit(0); break; default: ui.Print("Wrong input"); break; } }
public string AskForString(string prompt) { bool correct = true; string answer; do { ui.Print(prompt); answer = ui.GetString(); if (!string.IsNullOrEmpty(answer)) { correct = false; } } while (correct); return(answer); }
internal void Run() { menyOptions = GetMenyOptions(); do { Console.ReadKey(); ui.Clear(); ui.Print("Welcome"); ui.ShowMeny(); var input = util.AskForKey(""); if (menyOptions.ContainsKey(input)) { menyOptions[input]?.Invoke(); } } while (true); }
public static int AskForInt(string prompt, IUI ui) { bool success = false; int answer; do { string input = AskForString(prompt, ui); success = int.TryParse(input, out answer); //Om vi kan parsa inputen till en int = true annars false if (!success) { ui.Print("Only numbers"); } } while (!success); return(answer); }
internal static int AskForPositiveInt(string prompt, IUI ui) { bool success = false; int answer; do { string input = AskForString(prompt, ui); success = int.TryParse(input, out answer); if (!success || answer < 0) { ui.Print("You must give a postive integer"); } } while (!success || answer < 0); return(answer); }
internal static double AskForPositiveDouble(string prompt, IUI ui) { bool success = false; double answer; do { string input = AskForString(prompt, ui); success = double.TryParse(input, out answer); if (!success || answer <= 0) { ui.Print("You must give a postive decimal number"); } } while (!success || answer <= 0); return(answer); }
internal static int AskForInt(string prompt, IUI ui) { bool success = false; int answer; do { string input = AskForString(prompt, ui); success = int.TryParse(input, out answer); if (!success) { ui.Print("Wrong format"); } } while (!success); return(answer); }
internal static string AskForAlphabets(string prompt, IUI ui) { bool success = false; string answer; do { ui.Print(prompt); answer = ui.GetInput(); if (!string.IsNullOrEmpty(answer) && Regex.IsMatch(answer, @"^[a-zA-Z]+$")) { success = true; } } while (!success); return(answer); }
internal static string AskForString(string prompt, IUI ui) { bool success = false; string answer; do { ui.Print(prompt); answer = ui.GetInput(); if (!string.IsNullOrEmpty(answer)) { success = true; } } while (!success); return(answer); }
/// <summary> /// Prepares console, print menu, take command from user, check if is right and execute it. /// </summary> /// <param name="ui">IUI that prints massages.</param> /// <param name="commandFactory">Command to execute.</param> public static void Start(IUI ui, CommandFactory commandFactory) { ui.Initialize(); while (true) { ui.ReInitizlize(); string commandToExecute = ui.ReadLine(); if (Globals.MenuCommandTypesValue.ContainsKey(commandToExecute)) { var command = commandFactory.GetMenuCommand(commandToExecute, ui, Globals.MenuCommandTypesValue); command.Execute(); } else { ui.Print(Messages.WrongMessage, "Message"); } } }
{//Prompt = det vi vill skriva ut på skärmen //Ui hanterar utskrift public static string AskForString(string prompt, IUI ui) { bool success = false; string answer; //loopa tills användaren har skrivit in något //Än så länge ingen annan validering do { Console.WriteLine(prompt); answer = ui.GetInput(); if (String.IsNullOrWhiteSpace(answer)) { ui.Print("You must enter something"); } else { success = true; } } while (!success); return(answer); }
private void FindVehicleByRegNr() { bool regNrExist = false; do { string regNr = ui.AskForString("Please enter the registration number of the vehicle!"); try { var vehicleToFind = handler.FindVehicleByRegNr(regNr); if (regNr.Equals(regNr, StringComparison.InvariantCultureIgnoreCase)) { Console.Clear(); ui.Print($"The vehicle yo searched for is a {vehicleToFind.Color} {vehicleToFind.GetType().Name}, that has {vehicleToFind.NrOfWheels} wheels "); regNrExist = true; } } catch (NullReferenceException) { int input1 = ui.AskForInteger($"There is no vehicle in the garage that has this registration number: \u0022{regNr}\u0022. Please try again." + $"\n Press 1 to try again" + "\n press 2 to go back"); switch (input1) { case 1: regNrExist = false; break; case 2: regNrExist = true; Console.Clear(); break; } } } while (!regNrExist); }
private void MainMenu() { while (true) { ui.Print("Please navigate through the menu by inputting " + "the number \n(1, 2, 3 ,4, 5, 6, 0) of your choice" + "\n1. Add Vehicle" + "\n2. Remove Vehicle" + "\n3. Display all parked Vehicles" + "\n4. Display number of Vehicles" + "\n5. Search Vehicle based on the registration number" + "\n6. Search Vehicle based on the color, the number of wheels or types" + "\n0. Exit the application"); char input = ' '; try { input = Console.ReadLine()[0]; } catch (IndexOutOfRangeException) { Console.Clear(); ui.Print("Please enter some input!"); } switch (input) { case '1': AddVehicleMenu(); break; case '2': RemoveVehicle(); break; case '3': DisplayParkedVehicles(); //$"The number of parked vehicles: {}"; break; case '4': DisplayNumberOfVehicles(); //$"The number of vehicles: {}"; break; case '5': SearchVechicleRegNo(); break; case '6': SearchVehicleProperties(); break; case '0': Environment.Exit(0); break; default: ui.Print("Please enter some valid input (0, 1, 2, 3, 4, 5, 6)"); break; } } }
public void PrintMenu() { do { ui.Print("1. Populate the garage with som vehicles " + "\n2. Print all vehicles in the garage " + "\n3. Print vehicle types and how many of each there are in the garage" + "\n4. Park a vehicle " + "\n5. Pick up a vehicle" + "\n6. Get information about the vehicle by giving the registration number" + "\n7. Get a group of vehicles with certain attributes" + "\nQ. Quit application"); switch (ui.GetInput()) { case "1": SeedData(); break; case "2": PrintAll(); break; case "3": PrintVehicleTypes(); break; case "4": Park(); break; case "5": PickUp(); break; case "6": FindVehicleWithRegNr(); break; case "7": FindVehicle(); break; case "Q": Environment.Exit(0); break; default: ui.Print("Wrong choice, try again"); break; } ; } while (true); }
public void Do() { ui.Print("Hej"); }
public void AddVehicleByOption() { var list = garageHandler.garage.Vehicles; ui.Print("Välj vilket fordon du vill lägga till? " + "\n1. Airplane " + "\n2. MotorCycle" + "\n3. Car" + "\n4. Bus" + "\n5. Boat" + "\n6 Exit"); string option = ui.GetInput(); if (garageHandler.garage.IsFull()) { ui.Print("Garage is now full"); } else { switch (option) { case "1": AddAirplane(); ui.Print(" "); ui.Print("Airplane is parked"); ui.Print(" "); break; case "2": AddMotorcycle(); ui.Print(" "); ui.Print("Motorcycle is parked"); ui.Print(" "); break; case "3": AddCar(); ui.Print(" "); ui.Print("Car is parked"); ui.Print(" "); break; case "4": AddBus(); ui.Print(" "); ui.Print("Bus is parked"); ui.Print(" "); break; case "5": AddBoat(); ui.Print(" "); ui.Print("Boat is parked"); ui.Print(" "); break; case "6": Environment.Exit(0); break; default: ui.WrongInput("Wrong input, you must choose 1, 2, 3, 4 or 5"); break; } } }