Vapio

task26

Apr 22nd, 2021 (edited)
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Program
  5. {
  6.     public static void Main()
  7.     {
  8.         Dictionary<string, string> persons = new Dictionary<string, string>();
  9.  
  10.         string choose;
  11.         bool isRun = true;
  12.         while (isRun)
  13.         {
  14.             Console.WriteLine("\nInput number of action : ");
  15.             Console.WriteLine("1. Add case.\n" +
  16.                               "2. Output all cases.\n" +
  17.                               "3. Remove case.\n" +
  18.                               "4. Exit.");
  19.  
  20.             choose = Console.ReadLine();
  21.             switch (choose)
  22.             {
  23.                 case "1":
  24.                     AddCase(persons);
  25.                     break;
  26.                 case "2":
  27.                     OutputCases(persons);
  28.                     break;
  29.                 case "3":
  30.                     RemoveCase(persons);
  31.                     break;
  32.                 case "4":
  33.                     isRun = false;
  34.                     break;
  35.                 default:
  36.                     Console.WriteLine("You write wrong number of command.");
  37.                     break;
  38.             }
  39.         }
  40.     }
  41.  
  42.     public static void AddCase(Dictionary<string, string> persons)
  43.     {
  44.         string name;
  45.         string position;
  46.         Console.WriteLine("Input name of person : ");
  47.         name = Console.ReadLine();
  48.         Console.WriteLine("Input position of person : ");
  49.         position = Console.ReadLine();
  50.         persons.Add(name, position);
  51.     }
  52.  
  53.     public static void OutputCases(Dictionary<string, string> persons)
  54.     {
  55.         int i = 1;
  56.         foreach (KeyValuePair<string, string> person in persons)
  57.         {
  58.             Console.Write($"{i}. {person.Key} - {person.Value} ");
  59.             ++i;
  60.         }
  61.         Console.WriteLine();
  62.     }
  63.  
  64.     public static void RemoveCase(Dictionary<string, string> persons)
  65.     {
  66.         if (persons.Count != 0)
  67.         {
  68.             string personName;
  69.             bool isInput = true;
  70.  
  71.             do
  72.             {
  73.                 Console.WriteLine($"Amount of cases : {persons.Count}");
  74.                 Console.WriteLine("Please type a name of person : ");
  75.                 personName = Console.ReadLine();
  76.                 if (persons.ContainsKey(personName))
  77.                     isInput = false;
  78.             } while (isInput);
  79.  
  80.             persons.Remove(personName);
  81.         }
  82.     }
  83. }
Add Comment
Please, Sign In to add comment