Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace IMJunior
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<GoalsStorage> goalsLists = new List<GoalsStorage>();
- goalsLists.Add(new GoalsStorage("Личный"));
- goalsLists.Add(new GoalsStorage("Рабочий"));
- goalsLists.Add(new GoalsStorage("Семейный"));
- while (true)
- {
- Console.Clear();
- //поиск длинны самого длинного списка на данный момент
- int max = GetLongestArraySize(goalsLists);
- PrintHeader(goalsLists);
- for (int i = 0; i < max; i++)
- {
- foreach (var goalsList in goalsLists)
- goalsList.WriteGoal(i);
- Console.WriteLine();
- }
- Console.WriteLine("Куда вы хотите добавить цель?");
- string listName = Console.ReadLine(); //то что введёт пользователь переведённое в нижний регистр
- Console.WriteLine("Что это за цель?");
- string goalText = Console.ReadLine();
- //Здесь нельзя использовать Array.Resize
- AddGoal(listName, goalText, goalsLists);
- }
- }
- private static void PrintHeader(List<GoalsStorage> storages)
- {
- foreach (var storage in storages)
- Console.Write(storage.Name + " | ");
- Console.WriteLine();
- }
- private static int GetLongestArraySize(List<GoalsStorage> storages)
- {
- int max = int.MinValue;
- foreach (var storage in storages)
- if (storage.Length > max)
- max = storage.Length;
- return max;
- }
- private static void AddGoal(string storageName, string goalText, List<GoalsStorage> storages)
- {
- foreach (var storage in storages)
- if(storageName.ToLower() == storage.Name.ToLower())
- {
- storage.Add(goalText);
- break;
- }
- }
- }
- class GoalsStorage
- {
- public string Name { get; }
- public int Length => _goals.Length;
- private Goal[] _goals = new Goal[0];
- public GoalsStorage(string name)
- {
- Name = name;
- }
- public void Add(string goalText)
- {
- Goal[] goalsArrayNew = new Goal[_goals.Length + 1];
- for (int j = 0; j < _goals.Length; j++)
- goalsArrayNew[j] = _goals[j];
- goalsArrayNew[goalsArrayNew.Length - 1] = new Goal(goalText);
- _goals = goalsArrayNew;
- }
- public void WriteGoal(int index)
- {
- if (_goals.Length > index)
- Console.Write(_goals[index].Text + " | ");
- else
- Console.Write("Empty | ");
- }
- }
- class Goal
- {
- public string Text;
- public Goal(string text)
- {
- Text = text;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement