Advertisement
OldBeliver

Collection_04ver03

Apr 5th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace soccerTeam_01
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<string> teamBarselona;
  14.             List<string> fieldPosition;
  15.  
  16.             bool exit = false;
  17.             string userInput;
  18.  
  19.             GetSoccerTeam(out teamBarselona, out fieldPosition);
  20.  
  21.             while (exit == false)
  22.             {
  23.                 Console.WriteLine($"1 - Добавить досье\n2 - Вывести все досье\n3 - Удалить досье\n4 - Выход");
  24.                 userInput = Console.ReadLine();
  25.  
  26.                 switch (userInput)
  27.                 {
  28.                     case "1":
  29.                         Console.WriteLine($"Добавление нового игрока\n");
  30.                         AddRecords(teamBarselona, fieldPosition);
  31.                         break;
  32.                     case "2":
  33.                         Console.WriteLine($"Футбольный клуб Барселона\n");
  34.                         ShowRecords(teamBarselona, fieldPosition);
  35.                         break;
  36.                     case "3":
  37.                         Console.Write($"Для удаления на скамейку запасных введите порядковый номер игрока: ");
  38.                         DeleteRecord(teamBarselona, fieldPosition);
  39.                         break;
  40.                     case "4":
  41.                         exit = true;
  42.                         break;
  43.                 }
  44.                 Console.Write($"Нажмите любую клавишу для продолжения");
  45.                 Console.ReadKey();
  46.                 Console.Clear();
  47.             }
  48.         }
  49.  
  50.         static void GetSoccerTeam(out List<string> teamBarselona, out List<string> fieldPosition)
  51.         {
  52.             teamBarselona = new List<string>();
  53.             fieldPosition = new List<string>();
  54.  
  55.             teamBarselona.Add("Френки де Йонг");
  56.             fieldPosition.Add("полузащитник");
  57.             teamBarselona.Add("Лионель Месси");
  58.             fieldPosition.Add("нападающий");
  59.             teamBarselona.Add("Жорди Альба");
  60.             fieldPosition.Add("защитник");
  61.             teamBarselona.Add("Педри");
  62.             fieldPosition.Add("полузащитник");
  63.             teamBarselona.Add("Антуан Гризманн");
  64.             fieldPosition.Add("нападающий");
  65.             teamBarselona.Add("Клеман Лангле");
  66.             fieldPosition.Add("защитник");
  67.             teamBarselona.Add("Серджи Бускетс");
  68.             fieldPosition.Add("полузащитник");
  69.             teamBarselona.Add("Серджиньо Дест");
  70.             fieldPosition.Add("защитник");
  71.             teamBarselona.Add("Оскар Мингеса");
  72.             fieldPosition.Add("защитник");
  73.             teamBarselona.Add("Усман Дембеле");
  74.             fieldPosition.Add("полузащитник");
  75.             teamBarselona.Add("Мартин Брэйтуэйт");
  76.             fieldPosition.Add("нападающий");
  77.             teamBarselona.Add("Нето");
  78.             fieldPosition.Add("вратарь");
  79.         }
  80.  
  81.         static void ShowRecords(List<string> teamBarselona, List<string> fieldPosition)
  82.         {
  83.             for (int i = 0; i < teamBarselona.Count; i++)
  84.             {
  85.                 Console.WriteLine($"{i + 1}. {teamBarselona[i]} - {fieldPosition[i]}");
  86.             }
  87.         }
  88.  
  89.         static void AddRecords(List<string> teamBarselona, List<string> fieldPosition)
  90.         {
  91.             Console.Write($"Введите ФИО игрока: ");
  92.             string fullName = Console.ReadLine();
  93.             teamBarselona.Add(fullName);
  94.  
  95.             Console.Write($"Введите позицию на футбольном поле: ");
  96.             string position = Console.ReadLine();
  97.             fieldPosition.Add(position);
  98.  
  99.             Console.WriteLine($"Добавлена новая запись: {fullName} - {position}");
  100.         }
  101.  
  102.         static void DeleteRecord(List<string> teamBarselona, List<string> fieldPosition)
  103.         {
  104.             bool readInt = int.TryParse(Console.ReadLine(), out int indexForDelete);
  105.  
  106.             if (readInt == true)
  107.             {
  108.                 if(indexForDelete > 0 && indexForDelete <= teamBarselona.Count)
  109.                 {
  110.                     string deleteMessage = teamBarselona[indexForDelete - 1] + " " + fieldPosition[indexForDelete - 1];
  111.                     teamBarselona.RemoveAt(indexForDelete - 1);
  112.                     fieldPosition.RemoveAt(indexForDelete - 1);
  113.                     Console.WriteLine($"Игрок {deleteMessage} удален");
  114.                 }
  115.                 else
  116.                 {
  117.                     Console.WriteLine($"Число {indexForDelete} вне диапазона");
  118.                 }
  119.             }
  120.             else
  121.             {
  122.                 Console.WriteLine($"Это не число");
  123.             }            
  124.         }
  125.     }
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement