public void Start() { //loop for displaying always the menu int choiceSwitch = -1; while (choiceSwitch != 0) { //show the Menu by calling its method WriteMenuText(); //read input from the user and match it with switch cases choiceSwitch = Input.ReadIntegerConsole(); /*depending on the value of the choice, create an instance of * the class displayed on the menu */ switch (choiceSwitch) { //create whole numbers object if option 1 is chosen case 1: WholeNumbersForAdd wholeNumbersForAdd = new WholeNumbersForAdd(); wholeNumbersForAdd.Start(); break; //create floating point object if option 2 is chosen case 2: FloatingPointsNumberWhileAdd floatingPointsNumberWhileAdd = new FloatingPointsNumberWhileAdd(); floatingPointsNumberWhileAdd.Start(); break; //create currency converter object if option 3 is chosen case 3: CurrencyConverter currencyConverter = new CurrencyConverter(); currencyConverter.Start(); break; // create working schedule object if option 4 is chosen case 4: WorkingSchedule workingSchedule = new WorkingSchedule(); workingSchedule.Start(); break; //create temperature object if option 5 is chosen(optional requirement) case 5: Temperature temperature = new Temperature(); temperature.Start(); break; //exit the program if option 0 is chosen case 0: Environment.Exit(0); break; //wait for correct input if the user inserts an inexistent option default: Console.WriteLine("Invalid Choice"); break; } } }
private void WriteMenuText() { while (true) //endless loop { Console.Write("\t\tMAIN MENU\n\n" + "Whole Numbers with For\t\t\t: 1\n" + "Floating Point Numbers with While\t: 2\n" + "Currency Converter with Do While Loop\t: 3\n" + "Work Schedule\t\t\t\t: 4\n" + "Temperature Table\t\t\t: 5\n" + "Exit the program\t\t\t: 0\n\n" + "Your choice: "); switch (Console.ReadLine()) { case "1": var wholeNumbersForAdd = new WholeNumbersForAdd(); wholeNumbersForAdd.Start(); break; case "2": var floatingPointsNumberWhileAdd = new FloatingPointsNumberWhileAdd(); floatingPointsNumberWhileAdd.Start(); break; case "3": var currencyConverter = new CurrencyConverter(); currencyConverter.Start(); break; case "4": var workingSchedule = new WorkingSchedule(); workingSchedule.Start(); break; case "5": var temperatureTable = new TemperatureTable(); temperatureTable.Start(); break; case "0": return; default: Console.WriteLine("\nInvalid input, try again\n"); break; } } }
/// <summary> /// The Start method in the menu. It loops and keeps requesting input from the user as long as it is not in line with any of the options. /// If the choice is 0 the program will end. If 1-4 is input another class will be initiated. /// </summary> public void Start() { int choice = -1; while (choice != 0) { WriteMenuText(); choice = int.Parse(Console.ReadLine()); switch (choice) { case 1: { WholeNumbersForAdd sumObj = new WholeNumbersForAdd(); sumObj.Start(); break; } case 2: { FloatingPointsNumberWhileAdd floatWhile = new FloatingPointsNumberWhileAdd(); floatWhile.Start(); break; } case 3: { CurrencyConverter currencyConverter = new CurrencyConverter(); currencyConverter.Start(); break; } case 4: { WorkingSchedule workingSchedule = new WorkingSchedule(); workingSchedule.Start(); break; } } } }
public void Start() { CostumConsole(); int choise = -1; while (choise != 0) { WriteMenuText(); //Read the user input choise = Input.ReadIntegerConsole(); //Depending on the users input, creats an instance of the class displayed on the menu. switch (choise) { case 1: //Menu item 1 WholeNumbersForAdd sumObj = new WholeNumbersForAdd(); sumObj.Start(); break; case 2: //Menu item 2 FloatingPointsNumberWhileAdd sumFload = new FloatingPointsNumberWhileAdd(); sumFload.Start(); break; case 3: //Menu item 3 CurrencyConverter converter = new CurrencyConverter(); converter.Start(); break; case 4: //Menu item 4 WorkingSchedule workingSchedule = new WorkingSchedule(); workingSchedule.Start(); break; case 5: //Menu item 5 Temperatures temperatures = new Temperatures(); temperatures.Start(); break; } } }
private void RunChoice(string choice) { Startable subprogram = new NullAction(); // This subprograms does nothing. switch (choice) { case "0": Console.WriteLine("This can't happen!"); // Can't happen because we will not call the // method if choice == 0. break; case "1": subprogram = new WholeNumbersForAdd(); break; case "2": subprogram = new FloatingPointsNumberWhileAdd(); break; case "3": subprogram = new CurrencyConverter(); break; case "4": subprogram = new WorkingSchedule(); break; case "5": subprogram = new TempTable(); break; default: Console.WriteLine("Invalid choice"); break; } subprogram.Start(); } // RunChoice
/* Starts a certain program based on the input entered by the user. */ private void HandleInput() { switch (menuChoice) { case 0: enableMenu = false; break; case 1: WholeNumbersForAdd wholeNumbersForAdd = new WholeNumbersForAdd(); wholeNumbersForAdd.Start(); break; case 2: FloatingPointsNumberWhileAdd floatingPointsNumberWhileAdd = new FloatingPointsNumberWhileAdd(); floatingPointsNumberWhileAdd.Start(); break; case 3: CurrencyConverter currencyConverter = new CurrencyConverter(); currencyConverter.Start(); break; case 4: TemperatureTable temperatureTable = new TemperatureTable(); temperatureTable.Start(); break; case 5: WorkScheduleMenu workScheduleMenu = new WorkScheduleMenu(); workScheduleMenu.Start(); break; } ; }