-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
86 lines (82 loc) · 4.15 KB
/
Program.cs
File metadata and controls
86 lines (82 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dogs
{
class Program
{
const string path = @"C:\Users\hp\Desktop\Новая папка\Dogs\";
static void Main(string[] args)
{
List<Dog> list = ConsoleHelper.InputData();
ConsoleHelper.PrintToConsole(list);
int responce;
do
{
Console.WriteLine("Что вы хотите сделать?" +
"\n1 - Добавить инфо о собаке" +
"\n2 - Выполнить поиск собак по породе, допущенных к разведению" +
"\n3 - Сохранить все данные в файл" +
"\n4 - Редактировать данные о собаке " +
"\n5 - Удалить данные о собаке " +
"\n0 - Завершение работы");
int.TryParse(Console.ReadLine(), out responce);
switch (responce)
{
case 1:
list = list.Concat(ConsoleHelper.InputData()).ToList();
ConsoleHelper.PrintToConsole(list);
break;
case 2:
Console.WriteLine("Будет выведена информация о собаках, которые допущены " +
"\nк разведению (оценка выше не ниже очень хор), заданной породы," +
"\n упорядоченные по возрасту");
Console.ReadLine();
List<Dog> sortedList = SortDogs(list);
Console.WriteLine("Количество подходящих собак: "+ sortedList.Count);
ConsoleHelper.PrintToConsole(sortedList);
break;
case 3:
string name;
IFileManager file = ConsoleHelper.ChooseFile(out name);
file.PrintToFile(list, path + name);
Console.WriteLine("Запись выполнена");
break;
case 4:
Console.ReadLine();
Console.WriteLine("Выберите какой элемент вы хотите редактрировать, начиная с 0");
int edIndex;
int.TryParse(Console.ReadLine(), out edIndex);
list.Insert(edIndex, ConsoleHelper.EditCar(list, edIndex));
Console.WriteLine("Редактирование завершено");
Console.ReadLine();
ConsoleHelper.PrintToConsole(list);
break;
case 5:
Console.ReadLine();
Console.WriteLine("Выберите какой элемент удалить, начиная с 0");
int resp;
int.TryParse(Console.ReadLine(), out resp);
list.RemoveAt(resp);
Console.WriteLine("Удаление завершено");
Console.ReadLine();
ConsoleHelper.PrintToConsole(list);
break;
}
}
while (responce != 0);
}
static List<Dog> SortDogs(List<Dog> list)
{
Console.WriteLine("Введите породу");
string breed = Console.ReadLine();
Console.WriteLine();
List<Dog> sortedList = list.Where(cn => cn.Breed == breed && (cn.Mark >= Marks.Очень_хор))
.OrderBy(item => item.Age)
.ToList();
return sortedList;
}
}
}