From 47093d1440cfe0124589c527ff520d553a8fcb7c Mon Sep 17 00:00:00 2001 From: K-Voland Date: Tue, 16 Oct 2018 13:40:35 +0400 Subject: [PATCH 01/24] lab_2 --- Lab_2/CourseApp.csproj | 8 ++++++++ Lab_2/llab2.cs | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 Lab_2/CourseApp.csproj create mode 100644 Lab_2/llab2.cs diff --git a/Lab_2/CourseApp.csproj b/Lab_2/CourseApp.csproj new file mode 100644 index 0000000..23df604 --- /dev/null +++ b/Lab_2/CourseApp.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/Lab_2/llab2.cs b/Lab_2/llab2.cs new file mode 100644 index 0000000..bc6c4a7 --- /dev/null +++ b/Lab_2/llab2.cs @@ -0,0 +1,45 @@ +using System; + +namespace CourseApp4 +{ + class Program4 + { + + static void Main(string[] args) + { + + double xn = 0.7; + double xk = 2.2; + double dx = 0.3; + double[] xx = {0.25, 0.36, 0.56, 0.94, 1.28}; + + Console.WriteLine ("Задание А"); + + for( double x=xn; x Date: Tue, 30 Oct 2018 13:45:09 +0400 Subject: [PATCH 02/24] lab_2_2 --- CourseApp.Tests/CourseApp.Tests.csproj | 19 +++++++++++ CourseApp.Tests/UnitTest1.cs | 15 +++++++++ CourseApp/Program.cs | 45 ++++++++++++++++++++++---- 3 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 CourseApp.Tests/CourseApp.Tests.csproj create mode 100644 CourseApp.Tests/UnitTest1.cs diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj new file mode 100644 index 0000000..a83039e --- /dev/null +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp2.1 + + false + + + + + + + + + + + + + diff --git a/CourseApp.Tests/UnitTest1.cs b/CourseApp.Tests/UnitTest1.cs new file mode 100644 index 0000000..99ead48 --- /dev/null +++ b/CourseApp.Tests/UnitTest1.cs @@ -0,0 +1,15 @@ +using System; +using Xunit; +using CourseApp; + +namespace CourseApp.Tests +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + fun() + } + } +} diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index c270f52..5fe790e 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,12 +1,45 @@ using System; - -namespace CourseApp + +namespace CourseApp4 { - class Program + class Program2 { + static double a = 1.2; + static double b = 0.48; + static void Main(string[] args) { - Console.WriteLine("Волошин Константин"); + + double xn = 0.7; + double xk = 2.2; + double dx = 0.3; + double[] xx = {0.25, 0.36, 0.56, 0.94, 1.28}; + + Console.WriteLine ("Задание А"); + + for( double x=xn; x Date: Tue, 30 Oct 2018 13:48:00 +0400 Subject: [PATCH 03/24] lab_2_3 --- Lab_2/CourseApp.csproj | 8 -------- Lab_2/llab2.cs | 45 ------------------------------------------ 2 files changed, 53 deletions(-) delete mode 100644 Lab_2/CourseApp.csproj delete mode 100644 Lab_2/llab2.cs diff --git a/Lab_2/CourseApp.csproj b/Lab_2/CourseApp.csproj deleted file mode 100644 index 23df604..0000000 --- a/Lab_2/CourseApp.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Exe - netcoreapp2.1 - - - diff --git a/Lab_2/llab2.cs b/Lab_2/llab2.cs deleted file mode 100644 index bc6c4a7..0000000 --- a/Lab_2/llab2.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; - -namespace CourseApp4 -{ - class Program4 - { - - static void Main(string[] args) - { - - double xn = 0.7; - double xk = 2.2; - double dx = 0.3; - double[] xx = {0.25, 0.36, 0.56, 0.94, 1.28}; - - Console.WriteLine ("Задание А"); - - for( double x=xn; x Date: Mon, 12 Nov 2018 03:34:28 +0400 Subject: [PATCH 04/24] lab_3 --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/UnitTest1.cs | 55 ++++++++++++++++++++++++-- CourseApp/Program.cs | 20 ++++++---- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index a83039e..d1218e9 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -13,7 +13,7 @@ - + diff --git a/CourseApp.Tests/UnitTest1.cs b/CourseApp.Tests/UnitTest1.cs index 99ead48..7208e86 100644 --- a/CourseApp.Tests/UnitTest1.cs +++ b/CourseApp.Tests/UnitTest1.cs @@ -6,10 +6,57 @@ namespace CourseApp.Tests { public class UnitTest1 { - [Fact] + [Fact] public void Test1() { - fun() - } + var res = Program.Fan(0.7,1.2,0.48); + Assert.Equal(0.326, res, 3); + + } + [Fact] + public void Test2() + { + var res = Program.Fan(1.0,1.2,0.48); + Assert.Equal(0.584, res, 3); + + } + [Fact] + public void Test3() + { + var res = Program.Fan(1.3,1.2,0.48); + Assert.Equal(0.968, res, 3); + + } + [Fact] + public void Test4() + { + var res = Program.Fan(1.6,1.2,0.48); + Assert.Equal(Double.NaN, res, 3); + + } + [Fact] + public void Test5() + { + var res = Program.Fan(1.9,1.2,0.48); + Assert.Equal(Double.NaN, res, 3); + + } + + double[] xx = {0.25, 0.36, 0.56, 0.94, 1.28}; + + [Fact] + public void Test6() + { + //int j = 0; + double[] o = new double[5] {0.082,0.122,0.229,0.528,0.930}; + foreach (int i in xx) + { + var res = Program.Fan(xx[i],1.2,0.48); + Assert.Equal(o[i], res, 3); + // i++; + } + + } + } -} +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 5fe790e..39ad8d6 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,14 +1,18 @@ using System; -namespace CourseApp4 +namespace CourseApp { - class Program2 + public class Program { - static double a = 1.2; - static double b = 0.48; static void Main(string[] args) { + + Console.WriteLine("Волошин Константин"); + + double a = 1.2; + double b = 0.48; + double xn = 0.7; double xk = 2.2; @@ -19,7 +23,7 @@ static void Main(string[] args) for( double x=xn; x Date: Mon, 12 Nov 2018 09:13:41 +0400 Subject: [PATCH 05/24] lab_3m --- CourseApp.Tests/UnitTest1.cs | 22 +++++++++------------- CourseApp/Program.cs | 10 +++------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/CourseApp.Tests/UnitTest1.cs b/CourseApp.Tests/UnitTest1.cs index 7208e86..1a47ef1 100644 --- a/CourseApp.Tests/UnitTest1.cs +++ b/CourseApp.Tests/UnitTest1.cs @@ -6,57 +6,53 @@ namespace CourseApp.Tests { public class UnitTest1 { + [Fact] public void Test1() { var res = Program.Fan(0.7,1.2,0.48); Assert.Equal(0.326, res, 3); - } + [Fact] public void Test2() { var res = Program.Fan(1.0,1.2,0.48); Assert.Equal(0.584, res, 3); - } + [Fact] public void Test3() { var res = Program.Fan(1.3,1.2,0.48); Assert.Equal(0.968, res, 3); - } + [Fact] public void Test4() { var res = Program.Fan(1.6,1.2,0.48); Assert.Equal(Double.NaN, res, 3); - } + [Fact] public void Test5() { var res = Program.Fan(1.9,1.2,0.48); Assert.Equal(Double.NaN, res, 3); - } double[] xx = {0.25, 0.36, 0.56, 0.94, 1.28}; [Fact] public void Test6() - { - //int j = 0; + { double[] o = new double[5] {0.082,0.122,0.229,0.528,0.930}; foreach (int i in xx) { var res = Program.Fan(xx[i],1.2,0.48); - Assert.Equal(o[i], res, 3); - // i++; - } - - } - + Assert.Equal(o[i], res, 3); + } + } } } \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 39ad8d6..990bf48 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -11,9 +11,7 @@ static void Main(string[] args) Console.WriteLine("Волошин Константин"); double a = 1.2; - double b = 0.48; - - + double b = 0.48; double xn = 0.7; double xk = 2.2; double dx = 0.3; @@ -23,8 +21,7 @@ static void Main(string[] args) for( double x=xn; x Date: Sun, 25 Nov 2018 22:59:04 +0300 Subject: [PATCH 06/24] lab_4 --- CourseApp.Tests/UnitTest1.cs | 2 +- CourseApp.Tests/UnitTest2.cs | 17 ++++++++++++++ CourseApp/Child.cs | 12 ++++++++++ CourseApp/NewRabbit.cs | 44 ++++++++++++++++++++++++++++++++++++ CourseApp/Program.cs | 9 ++++++-- CourseApp/Rabbit.cs | 26 +++++++++++++++++++++ 6 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 CourseApp.Tests/UnitTest2.cs create mode 100644 CourseApp/Child.cs create mode 100644 CourseApp/NewRabbit.cs create mode 100644 CourseApp/Rabbit.cs diff --git a/CourseApp.Tests/UnitTest1.cs b/CourseApp.Tests/UnitTest1.cs index 1a47ef1..84b1888 100644 --- a/CourseApp.Tests/UnitTest1.cs +++ b/CourseApp.Tests/UnitTest1.cs @@ -4,7 +4,7 @@ namespace CourseApp.Tests { - public class UnitTest1 + public class UnitTest1 { [Fact] diff --git a/CourseApp.Tests/UnitTest2.cs b/CourseApp.Tests/UnitTest2.cs new file mode 100644 index 0000000..853ba87 --- /dev/null +++ b/CourseApp.Tests/UnitTest2.cs @@ -0,0 +1,17 @@ +using System; +using Xunit; +using CourseApp; + +namespace CourseApp.Tests +{ + public class UnitTest2 + { + [Fact] + public void Test1() + { + var krosh = new NewRabbit(); + Assert.Equal(0.326, res, 3); + } + + } +} \ No newline at end of file diff --git a/CourseApp/Child.cs b/CourseApp/Child.cs new file mode 100644 index 0000000..28ed904 --- /dev/null +++ b/CourseApp/Child.cs @@ -0,0 +1,12 @@ +using System; + +namespace CourseApp +{ + public class Child + { + public Child() + { + + } + } +} \ No newline at end of file diff --git a/CourseApp/NewRabbit.cs b/CourseApp/NewRabbit.cs new file mode 100644 index 0000000..d398c48 --- /dev/null +++ b/CourseApp/NewRabbit.cs @@ -0,0 +1,44 @@ +using System; + +namespace CourseApp +{ + + class NewRabbit + { + public void NewRabbitt() + { + Rabbit ururu = new Rabbit( InName(), InColor(), InAge()); + ururu.RabbitInfo(); + } + + static string InName () + { + Console.Write("Введите имя: "); + string Name = Console.ReadLine(); + return Name; + } + + static int InAge () + { + Console.Write("Введите возраст: "); + int Age = Convert.ToInt32(Console.ReadLine()); + return Age; + } + + static string InColor () + { + Console.Write("Введите цвет: "); + string Color = Console.ReadLine(); + return Color; + } + public void art() + { + Console.WriteLine(@" + ------/)/)-----/),/)----(\__/)----(\.(\-----(\(\ + -----(':'=)----(':'=)---(=';'=)---(=':')----(=':') + --(')('),,)-(')('),,)---(')_(')---(..(')(')-(..(')(') "); + } + + + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 990bf48..e694ab9 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,10 +1,10 @@ using System; - + namespace CourseApp { public class Program { - + static void Main(string[] args) { @@ -31,6 +31,11 @@ static void Main(string[] args) Console.WriteLine (Fan(x,a,b)); } + Console.WriteLine ("Лабараторная по классам"); + NewRabbit ururu = new NewRabbit(); + ururu.NewRabbitt(); + ururu.art(); + } public static double Fan(double x, double a, double b) diff --git a/CourseApp/Rabbit.cs b/CourseApp/Rabbit.cs new file mode 100644 index 0000000..a947c70 --- /dev/null +++ b/CourseApp/Rabbit.cs @@ -0,0 +1,26 @@ +using System; + +namespace CourseApp +{ + public class Rabbit + { + + public string name; + public string color; + public int age; + + public Rabbit(string n,string c, int ag) + { + name = n; + color = c; + age = ag; + } + + + public void RabbitInfo() + { + Console.WriteLine($"Имя: {name} Цвет: {color} Возраст: {age}"); + } + } + +} From 297b5d6f0220619e7cf4d04e97951649b5169f3b Mon Sep 17 00:00:00 2001 From: User Date: Mon, 26 Nov 2018 12:56:09 +0300 Subject: [PATCH 07/24] lab_4_1 --- CourseApp.Tests/UnitTest2.cs | 36 ++++++++++++++++++++++++++++++++++-- CourseApp/NewRabbit.cs | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/CourseApp.Tests/UnitTest2.cs b/CourseApp.Tests/UnitTest2.cs index 853ba87..59aa750 100644 --- a/CourseApp.Tests/UnitTest2.cs +++ b/CourseApp.Tests/UnitTest2.cs @@ -9,8 +9,40 @@ public class UnitTest2 [Fact] public void Test1() { - var krosh = new NewRabbit(); - Assert.Equal(0.326, res, 3); + Rabbit krosh = new Rabbit("momo","rad",3); + var name = krosh.name; + var color = krosh.color; + var age = krosh.age; + + Assert.Equal("momo",name); + Assert.Equal("rad",color); + Assert.Equal(3,age); + } + + [Fact] + public void Test2() + { + Rabbit krosh = new Rabbit("rar","grin",1); + var name = krosh.name; + var color = krosh.color; + var age = krosh.age; + + Assert.Equal("rar",name); + Assert.Equal("grin",color); + Assert.Equal(1,age); + } + + [Fact] + public void Test3() + { + Rabbit krosh = new Rabbit("ggwp","blue",9); + var name = krosh.name; + var color = krosh.color; + var age = krosh.age; + + Assert.Equal("ggwp",name); + Assert.Equal("blue",color); + Assert.Equal(9,age); } } diff --git a/CourseApp/NewRabbit.cs b/CourseApp/NewRabbit.cs index d398c48..c3b55e2 100644 --- a/CourseApp/NewRabbit.cs +++ b/CourseApp/NewRabbit.cs @@ -3,7 +3,7 @@ namespace CourseApp { - class NewRabbit + public class NewRabbit { public void NewRabbitt() { From addc7ccb44a29d07f545375bb2d82aacfff96c3d Mon Sep 17 00:00:00 2001 From: User Date: Sat, 1 Dec 2018 09:02:20 +0300 Subject: [PATCH 08/24] lab_4_2_ujas --- CourseApp/Child.cs | 12 ------- CourseApp/Farm.cs | 24 ++++++++++++++ CourseApp/Menu.cs | 70 +++++++++++++++++++++++++++++++++++++++++ CourseApp/NewRabbit.cs | 44 -------------------------- CourseApp/Program.cs | 10 +++--- CourseApp/Rabbit.cs | 26 --------------- CourseApp/RabbitInfo.cs | 17 ++++++++++ CourseApp/map.cs | 16 ++++++++++ 8 files changed, 132 insertions(+), 87 deletions(-) delete mode 100644 CourseApp/Child.cs create mode 100644 CourseApp/Farm.cs create mode 100644 CourseApp/Menu.cs delete mode 100644 CourseApp/NewRabbit.cs delete mode 100644 CourseApp/Rabbit.cs create mode 100644 CourseApp/RabbitInfo.cs create mode 100644 CourseApp/map.cs diff --git a/CourseApp/Child.cs b/CourseApp/Child.cs deleted file mode 100644 index 28ed904..0000000 --- a/CourseApp/Child.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace CourseApp -{ - public class Child - { - public Child() - { - - } - } -} \ No newline at end of file diff --git a/CourseApp/Farm.cs b/CourseApp/Farm.cs new file mode 100644 index 0000000..20164ae --- /dev/null +++ b/CourseApp/Farm.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; + +namespace CourseApp +{ + + public class Farm + { + public string Name; + public string[] Pearent=new string[2]; + public string[] Child; + public Farm() {} + public Farm(string n) {Name=n;} + public Farm(string n, string[] p) {Name=n;Pearent[1]=p[1];Pearent[2]=p[2];} + public Farm(string n, string[] p, string[] ch) + { + Name=n;Pearent[1]=p[1]; + Pearent[2]=p[2]; + foreach (var i in ch){Child[Convert.ToInt32(i)]=ch[Convert.ToInt32(i)];}; + } + + + } +} \ No newline at end of file diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs new file mode 100644 index 0000000..4c22865 --- /dev/null +++ b/CourseApp/Menu.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace CourseApp +{ + public class Menu + { + public void menu() + { + var info = new Rabbit(); + // var farm = new Farm(); + List farm= new List(); + string go; + Console.WriteLine ("Добро пожаловать на кроличью ферму!"); + do { + go = Console.ReadLine(); + switch (go) + { + case "help": + help(); + break; + case "Buy": + Console.WriteLine ("Введите имя нового кролика"); + string Name = Console.ReadLine(); + farm.Add(new Farm(Name)); + break; + case "Select": + // Скоро будет + break; + case "Art": + art(); + break; + case "Info": + foreach (var i in farm) + { + info.RabbitInfo(i.Name); + } + break; + default: + Console.WriteLine("Такой команды не существует. help - узнать список команд."); + break; // Поправить вывод при стопе проги + }} + while (go != "Stop"); + } + + static void help() + { + Console.WriteLine(@" + Команды: + Stop - закончить программу; + Art - вывести рисунок кроликов; + Buy - купить нового кролика; + Select - выростить нового кролика; + Info - узнать ситуацию по кроликам + "); + } + static void art() + { + Console.WriteLine(@" + ------/)/)------/),/)----(\__/)---(\.(\-----(\(\ + -----(':'=)----(':'=)---(=';'=)---(=':')----(=':') + --(')('),,)-(')('),,)---(')_(')---(..(')(')-(..(')(') "); + } + + + + } +} + diff --git a/CourseApp/NewRabbit.cs b/CourseApp/NewRabbit.cs deleted file mode 100644 index c3b55e2..0000000 --- a/CourseApp/NewRabbit.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; - -namespace CourseApp -{ - - public class NewRabbit - { - public void NewRabbitt() - { - Rabbit ururu = new Rabbit( InName(), InColor(), InAge()); - ururu.RabbitInfo(); - } - - static string InName () - { - Console.Write("Введите имя: "); - string Name = Console.ReadLine(); - return Name; - } - - static int InAge () - { - Console.Write("Введите возраст: "); - int Age = Convert.ToInt32(Console.ReadLine()); - return Age; - } - - static string InColor () - { - Console.Write("Введите цвет: "); - string Color = Console.ReadLine(); - return Color; - } - public void art() - { - Console.WriteLine(@" - ------/)/)-----/),/)----(\__/)----(\.(\-----(\(\ - -----(':'=)----(':'=)---(=';'=)---(=':')----(=':') - --(')('),,)-(')('),,)---(')_(')---(..(')(')-(..(')(') "); - } - - - } -} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index e694ab9..d17768d 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -31,11 +31,11 @@ static void Main(string[] args) Console.WriteLine (Fan(x,a,b)); } - Console.WriteLine ("Лабараторная по классам"); - NewRabbit ururu = new NewRabbit(); - ururu.NewRabbitt(); - ururu.art(); + + Menu start = new Menu(); + start.menu(); + } public static double Fan(double x, double a, double b) @@ -43,7 +43,7 @@ public static double Fan(double x, double a, double b) double y = (b*b*b + Math.Sin(a*x)*Math.Sin(a*x)) / (Math.Acos(x*b*x) + Math.Exp(-x/2)); return y; } - + } } diff --git a/CourseApp/Rabbit.cs b/CourseApp/Rabbit.cs deleted file mode 100644 index a947c70..0000000 --- a/CourseApp/Rabbit.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; - -namespace CourseApp -{ - public class Rabbit - { - - public string name; - public string color; - public int age; - - public Rabbit(string n,string c, int ag) - { - name = n; - color = c; - age = ag; - } - - - public void RabbitInfo() - { - Console.WriteLine($"Имя: {name} Цвет: {color} Возраст: {age}"); - } - } - -} diff --git a/CourseApp/RabbitInfo.cs b/CourseApp/RabbitInfo.cs new file mode 100644 index 0000000..d99d75c --- /dev/null +++ b/CourseApp/RabbitInfo.cs @@ -0,0 +1,17 @@ +using System; + +namespace CourseApp +{ + public class Rabbit + { + public void RabbitInfo(string Name, string[] Pearent, string[] Child) + { + Console.Write($"Имя {Name} Родители: {Pearent[1]} и {Pearent[2]} Дети: "); + foreach (var i in Child) {Console.WriteLine(Child[Convert.ToInt32(i)]);} + } + public void RabbitInfo(string Name, string[] Pearent) {Console.WriteLine($"Имя {Name} Родители: {Pearent[1]} и {Pearent[2]}");} + public void RabbitInfo(string Name) {Console.WriteLine($"Имя {Name}");} + public void RabbitInfo() {Console.WriteLine("eror");} + } + +} diff --git a/CourseApp/map.cs b/CourseApp/map.cs new file mode 100644 index 0000000..9483c7a --- /dev/null +++ b/CourseApp/map.cs @@ -0,0 +1,16 @@ +using System; + +namespace CourseApp +{ + public class map + { + + public string Name; + public map() {} + public map(string krolik) + { + Name = krolik; + + } + } +} \ No newline at end of file From e3d4d8e8d1664650e21b1a37de90d54eeb4cc5e0 Mon Sep 17 00:00:00 2001 From: User Date: Sun, 2 Dec 2018 20:28:43 +0300 Subject: [PATCH 09/24] lab_4_3 --- CourseApp/Farm.cs | 14 ++++++++------ CourseApp/Menu.cs | 38 ++++++++++++++++++++++++-------------- CourseApp/Program.cs | 2 +- CourseApp/RabbitInfo.cs | 6 +++--- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/CourseApp/Farm.cs b/CourseApp/Farm.cs index 20164ae..fd15cf8 100644 --- a/CourseApp/Farm.cs +++ b/CourseApp/Farm.cs @@ -7,15 +7,17 @@ namespace CourseApp public class Farm { public string Name; - public string[] Pearent=new string[2]; + public string Pearent1; + public string Pearent2; public string[] Child; public Farm() {} - public Farm(string n) {Name=n;} - public Farm(string n, string[] p) {Name=n;Pearent[1]=p[1];Pearent[2]=p[2];} - public Farm(string n, string[] p, string[] ch) + public Farm(string n) {this.Name=n;} + public Farm(string n, string p1,string p2) {this.Name=n;this.Pearent1=p1;this.Pearent2=p1;} + public Farm(string n, string p1,string p2, string[] ch) { - Name=n;Pearent[1]=p[1]; - Pearent[2]=p[2]; + Name=n; + Pearent1=p1; + Pearent2=p2; foreach (var i in ch){Child[Convert.ToInt32(i)]=ch[Convert.ToInt32(i)];}; } diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index 4c22865..0797e36 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -1,17 +1,20 @@ using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections; namespace CourseApp { public class Menu { public void menu() - { + { //int j=0; var info = new Rabbit(); // var farm = new Farm(); - List farm= new List(); string go; + string Name; + string Pearent1; + string Pearent2; + ArrayList klet= new ArrayList(); + Console.WriteLine ("Добро пожаловать на кроличью ферму!"); do { go = Console.ReadLine(); @@ -21,25 +24,32 @@ public void menu() help(); break; case "Buy": - Console.WriteLine ("Введите имя нового кролика"); - string Name = Console.ReadLine(); - farm.Add(new Farm(Name)); + Console.Write("Введите имя купленного кролика: "); + Name = Console.ReadLine(); + klet.Add(new Farm(Name)); break; case "Select": - // Скоро будет + Console.Write ("Введите имя новорожденного кролика: "); + Name = Console.ReadLine(); + Console.WriteLine("Введите имена родителй кролика: "); + Pearent1=Console.ReadLine(); + Pearent2=Console.ReadLine(); + klet.Add(new Farm(Name,Pearent1,Pearent2)); break; case "Art": art(); break; - case "Info": - foreach (var i in farm) + case "Info": + foreach(Farm i in klet) { - info.RabbitInfo(i.Name); + if (i.Pearent1 != null) + {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2);} + else {info.RabbitInfo(i.Name);} } break; - default: - Console.WriteLine("Такой команды не существует. help - узнать список команд."); - break; // Поправить вывод при стопе проги + default: if(go != "Stop") { + Console.WriteLine("Такой команды не существует. help - узнать список команд.");} + break; }} while (go != "Stop"); } diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index d17768d..842a6b9 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -5,7 +5,7 @@ namespace CourseApp public class Program { - static void Main(string[] args) + static void Main() { Console.WriteLine("Волошин Константин"); diff --git a/CourseApp/RabbitInfo.cs b/CourseApp/RabbitInfo.cs index d99d75c..91a5aad 100644 --- a/CourseApp/RabbitInfo.cs +++ b/CourseApp/RabbitInfo.cs @@ -4,12 +4,12 @@ namespace CourseApp { public class Rabbit { - public void RabbitInfo(string Name, string[] Pearent, string[] Child) + public void RabbitInfo(string Name, string Pearent1,string Pearent2, string[] Child) { - Console.Write($"Имя {Name} Родители: {Pearent[1]} и {Pearent[2]} Дети: "); + Console.Write($"Имя {Name} Родители: {Pearent1} и {Pearent2} Дети: "); foreach (var i in Child) {Console.WriteLine(Child[Convert.ToInt32(i)]);} } - public void RabbitInfo(string Name, string[] Pearent) {Console.WriteLine($"Имя {Name} Родители: {Pearent[1]} и {Pearent[2]}");} + public void RabbitInfo(string Name, string Pearent1,string Pearent2) {Console.WriteLine($"Имя {Name} Родители: {Pearent1} и {Pearent2}");} public void RabbitInfo(string Name) {Console.WriteLine($"Имя {Name}");} public void RabbitInfo() {Console.WriteLine("eror");} } From 75548badda68734b3482efdf72ed9595ad91546c Mon Sep 17 00:00:00 2001 From: User Date: Sun, 2 Dec 2018 21:56:58 +0300 Subject: [PATCH 10/24] lab_4_4 --- CourseApp/Farm.cs | 14 ++++---- CourseApp/Menu.cs | 76 +++++++++++++++++++++++------------------ CourseApp/RabbitInfo.cs | 12 +++---- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/CourseApp/Farm.cs b/CourseApp/Farm.cs index fd15cf8..5df84b7 100644 --- a/CourseApp/Farm.cs +++ b/CourseApp/Farm.cs @@ -9,16 +9,16 @@ public class Farm public string Name; public string Pearent1; public string Pearent2; - public string[] Child; + public int Child; public Farm() {} public Farm(string n) {this.Name=n;} - public Farm(string n, string p1,string p2) {this.Name=n;this.Pearent1=p1;this.Pearent2=p1;} - public Farm(string n, string p1,string p2, string[] ch) + public Farm(string n, string p1,string p2) {this.Name=n;this.Pearent1=p1;this.Pearent2=p2;} + public Farm(string n, string p1,string p2, int ch) { - Name=n; - Pearent1=p1; - Pearent2=p2; - foreach (var i in ch){Child[Convert.ToInt32(i)]=ch[Convert.ToInt32(i)];}; + this.Name=n; + this.Pearent1=p1; + this.Pearent2=p2; + this.Child=ch; } diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index 0797e36..ba40994 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -5,10 +5,9 @@ namespace CourseApp { public class Menu { - public void menu() - { //int j=0; + public void menu() + { var info = new Rabbit(); - // var farm = new Farm(); string go; string Name; string Pearent1; @@ -19,41 +18,56 @@ public void menu() do { go = Console.ReadLine(); switch (go) - { - case "help": - help(); + { + case "help": + help(); + Console.WriteLine("----------"); break; - case "Buy": - Console.Write("Введите имя купленного кролика: "); - Name = Console.ReadLine(); - klet.Add(new Farm(Name)); + case "Buy": + Console.Write("Введите имя купленного кролика: "); + Name = Console.ReadLine(); + klet.Add(new Farm(Name)); + Console.WriteLine("----------"); break; - case "Select": - Console.Write ("Введите имя новорожденного кролика: "); - Name = Console.ReadLine(); - Console.WriteLine("Введите имена родителй кролика: "); - Pearent1=Console.ReadLine(); - Pearent2=Console.ReadLine(); - klet.Add(new Farm(Name,Pearent1,Pearent2)); + case "Select": + Console.Write ("Введите имя новорожденного кролика: "); + Name = Console.ReadLine(); + Console.WriteLine("Введите имена родителй кролика: "); + Pearent1=Console.ReadLine(); + Pearent2=Console.ReadLine(); + klet.Add(new Farm(Name,Pearent1,Pearent2)); + foreach(Farm i in klet) + { + if(Pearent1==i.Name||Pearent2==i.Name){i.Child=i.Child+1;}; + + } + Console.WriteLine("----------"); break; - case "Art": - art(); + case "Art": + art(); + Console.WriteLine("----------"); break; - case "Info": - foreach(Farm i in klet) - { - if (i.Pearent1 != null) + case "Info": int num=1; + foreach(Farm i in klet) + { + Console.Write($"{num++})"); + if (i.Pearent1 == null && i.Child == 0) + {info.RabbitInfo(i.Name);} + else if(i.Pearent1 != null && i.Child == 0) {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2);} - else {info.RabbitInfo(i.Name);} - } + else if(i.Pearent1 == null && i.Child != 0) + {info.RabbitInfo(i.Name,i.Child);} + else if(i.Pearent1 != null && i.Child != 0) + {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2,i.Child);} + } + Console.WriteLine("----------"); break; default: if(go != "Stop") { Console.WriteLine("Такой команды не существует. help - узнать список команд.");} break; - }} - while (go != "Stop"); + }} + while (go != "Stop"); } - static void help() { Console.WriteLine(@" @@ -72,9 +86,5 @@ static void art() -----(':'=)----(':'=)---(=';'=)---(=':')----(=':') --(')('),,)-(')('),,)---(')_(')---(..(')(')-(..(')(') "); } - - - } -} - +} \ No newline at end of file diff --git a/CourseApp/RabbitInfo.cs b/CourseApp/RabbitInfo.cs index 91a5aad..d866ee4 100644 --- a/CourseApp/RabbitInfo.cs +++ b/CourseApp/RabbitInfo.cs @@ -4,14 +4,10 @@ namespace CourseApp { public class Rabbit { - public void RabbitInfo(string Name, string Pearent1,string Pearent2, string[] Child) - { - Console.Write($"Имя {Name} Родители: {Pearent1} и {Pearent2} Дети: "); - foreach (var i in Child) {Console.WriteLine(Child[Convert.ToInt32(i)]);} - } - public void RabbitInfo(string Name, string Pearent1,string Pearent2) {Console.WriteLine($"Имя {Name} Родители: {Pearent1} и {Pearent2}");} - public void RabbitInfo(string Name) {Console.WriteLine($"Имя {Name}");} - public void RabbitInfo() {Console.WriteLine("eror");} + public void RabbitInfo(string Name, string Pearent1,string Pearent2, int Child) {Console.Write($"Кролик {Name} Родители: {Pearent1} и {Pearent2} Детей: {Child}");} + public void RabbitInfo(string Name, string Pearent1,string Pearent2) {Console.WriteLine($"Кролик {Name} Родители: {Pearent1} и {Pearent2}");} + public void RabbitInfo(string Name) {Console.WriteLine($"Кролик {Name}");} + public void RabbitInfo(string Name, int Child) {Console.WriteLine($"Кролик {Name} Детей: {Child}");} } } From 40078f87b5573e33ccbb8a62ff994df5817cdbec Mon Sep 17 00:00:00 2001 From: User Date: Sun, 2 Dec 2018 22:38:44 +0300 Subject: [PATCH 11/24] lab_4_5 --- CourseApp/Farm.cs | 4 ---- CourseApp/Menu.cs | 34 ++++++++++++++++++++++------------ CourseApp/RabbitInfo.cs | 11 +++++------ 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/CourseApp/Farm.cs b/CourseApp/Farm.cs index 5df84b7..33b6f00 100644 --- a/CourseApp/Farm.cs +++ b/CourseApp/Farm.cs @@ -1,9 +1,7 @@ using System; -using System.Collections.Generic; namespace CourseApp { - public class Farm { public string Name; @@ -20,7 +18,5 @@ public Farm(string n, string p1,string p2, int ch) this.Pearent2=p2; this.Child=ch; } - - } } \ No newline at end of file diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index ba40994..03b5238 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -29,7 +29,7 @@ public void menu() klet.Add(new Farm(Name)); Console.WriteLine("----------"); break; - case "Select": + case "Sel": Console.Write ("Введите имя новорожденного кролика: "); Name = Console.ReadLine(); Console.WriteLine("Введите имена родителй кролика: "); @@ -50,17 +50,26 @@ public void menu() case "Info": int num=1; foreach(Farm i in klet) { - Console.Write($"{num++})"); - if (i.Pearent1 == null && i.Child == 0) - {info.RabbitInfo(i.Name);} - else if(i.Pearent1 != null && i.Child == 0) - {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2);} - else if(i.Pearent1 == null && i.Child != 0) - {info.RabbitInfo(i.Name,i.Child);} - else if(i.Pearent1 != null && i.Child != 0) - {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2,i.Child);} + Console.Write($"{num++}) {i.Name}"); } Console.WriteLine("----------"); + break; + case "Inf": + { Console.Write("Введите имя кролика о котором хотите унать: "); + Name = Console.ReadLine(); + foreach(Farm i in klet) + {if(i.Name==Name){ + if (i.Pearent1 == null && i.Child == 0) + {info.RabbitInfo(i.Name);} + else if(i.Pearent1 != null && i.Child == 0) + {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2);} + else if(i.Pearent1 == null && i.Child != 0) + {info.RabbitInfo(i.Name,i.Child);} + else if(i.Pearent1 != null && i.Child != 0) + {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2,i.Child);} + }} + Console.WriteLine("----------"); + } break; default: if(go != "Stop") { Console.WriteLine("Такой команды не существует. help - узнать список команд.");} @@ -75,8 +84,9 @@ static void help() Stop - закончить программу; Art - вывести рисунок кроликов; Buy - купить нового кролика; - Select - выростить нового кролика; - Info - узнать ситуацию по кроликам + Sel - выростить нового кролика; + Info - узнать имена всех кроликов + Inf - узнать о конкретном кролике "); } static void art() diff --git a/CourseApp/RabbitInfo.cs b/CourseApp/RabbitInfo.cs index d866ee4..4abdf88 100644 --- a/CourseApp/RabbitInfo.cs +++ b/CourseApp/RabbitInfo.cs @@ -4,10 +4,9 @@ namespace CourseApp { public class Rabbit { - public void RabbitInfo(string Name, string Pearent1,string Pearent2, int Child) {Console.Write($"Кролик {Name} Родители: {Pearent1} и {Pearent2} Детей: {Child}");} - public void RabbitInfo(string Name, string Pearent1,string Pearent2) {Console.WriteLine($"Кролик {Name} Родители: {Pearent1} и {Pearent2}");} - public void RabbitInfo(string Name) {Console.WriteLine($"Кролик {Name}");} - public void RabbitInfo(string Name, int Child) {Console.WriteLine($"Кролик {Name} Детей: {Child}");} + public void RabbitInfo(string Name, string Pearent1,string Pearent2, int Child) {Console.Write($"Кролик {Name}, Родители: {Pearent1} и {Pearent2}, Детей: {Child}");} + public void RabbitInfo(string Name, string Pearent1,string Pearent2) {Console.WriteLine($"Кролик {Name}, Родители: {Pearent1} и {Pearent2}, Детей нет");} + public void RabbitInfo(string Name) {Console.WriteLine($"Кролик {Name}, Родители: ??? и ???, Детей нет");} + public void RabbitInfo(string Name, int Child) {Console.WriteLine($"Кролик {Name}, Родители: ??? и ???, Детей: {Child}");} } - -} +} \ No newline at end of file From 2f38d04e63536a6a265e82d68b250082ac18f66a Mon Sep 17 00:00:00 2001 From: User Date: Sun, 2 Dec 2018 23:13:02 +0300 Subject: [PATCH 12/24] lab_4_6 --- CourseApp/Farm.cs | 5 +++-- CourseApp/Menu.cs | 14 +++++++------- CourseApp/RabbitInfo.cs | 9 ++++++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CourseApp/Farm.cs b/CourseApp/Farm.cs index 33b6f00..bb7176e 100644 --- a/CourseApp/Farm.cs +++ b/CourseApp/Farm.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace CourseApp { @@ -7,11 +8,11 @@ public class Farm public string Name; public string Pearent1; public string Pearent2; - public int Child; + public List Child=new List(); public Farm() {} public Farm(string n) {this.Name=n;} public Farm(string n, string p1,string p2) {this.Name=n;this.Pearent1=p1;this.Pearent2=p2;} - public Farm(string n, string p1,string p2, int ch) + public Farm(string n, string p1,string p2, List ch) { this.Name=n; this.Pearent1=p1; diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index 03b5238..5a48a98 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; namespace CourseApp { @@ -38,8 +39,7 @@ public void menu() klet.Add(new Farm(Name,Pearent1,Pearent2)); foreach(Farm i in klet) { - if(Pearent1==i.Name||Pearent2==i.Name){i.Child=i.Child+1;}; - + if(Pearent1==i.Name||Pearent2==i.Name){i.Child.Add(Name);}; } Console.WriteLine("----------"); break; @@ -50,7 +50,7 @@ public void menu() case "Info": int num=1; foreach(Farm i in klet) { - Console.Write($"{num++}) {i.Name}"); + Console.WriteLine($"{num++}) {i.Name}"); } Console.WriteLine("----------"); break; @@ -59,13 +59,13 @@ public void menu() Name = Console.ReadLine(); foreach(Farm i in klet) {if(i.Name==Name){ - if (i.Pearent1 == null && i.Child == 0) + if (i.Pearent1 == null && i.Child.Count == 0) {info.RabbitInfo(i.Name);} - else if(i.Pearent1 != null && i.Child == 0) + else if(i.Pearent1 != null && i.Child.Count == 0) {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2);} - else if(i.Pearent1 == null && i.Child != 0) + else if(i.Pearent1 == null && i.Child.Count != 0) {info.RabbitInfo(i.Name,i.Child);} - else if(i.Pearent1 != null && i.Child != 0) + else if(i.Pearent1 != null && i.Child.Count != 0) {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2,i.Child);} }} Console.WriteLine("----------"); diff --git a/CourseApp/RabbitInfo.cs b/CourseApp/RabbitInfo.cs index 4abdf88..f8b531b 100644 --- a/CourseApp/RabbitInfo.cs +++ b/CourseApp/RabbitInfo.cs @@ -1,12 +1,15 @@ using System; +using System.Collections.Generic; namespace CourseApp { public class Rabbit { - public void RabbitInfo(string Name, string Pearent1,string Pearent2, int Child) {Console.Write($"Кролик {Name}, Родители: {Pearent1} и {Pearent2}, Детей: {Child}");} + public void RabbitInfo(string Name, string Pearent1,string Pearent2, List Child) + {Console.Write($"Кролик {Name}, Родители: {Pearent1} и {Pearent2}, Дети: ");foreach(var i in Child){Console.WriteLine($"{i} ");}} public void RabbitInfo(string Name, string Pearent1,string Pearent2) {Console.WriteLine($"Кролик {Name}, Родители: {Pearent1} и {Pearent2}, Детей нет");} - public void RabbitInfo(string Name) {Console.WriteLine($"Кролик {Name}, Родители: ??? и ???, Детей нет");} - public void RabbitInfo(string Name, int Child) {Console.WriteLine($"Кролик {Name}, Родители: ??? и ???, Детей: {Child}");} + public void RabbitInfo(string Name) {Console.WriteLine($"Кролик {Name}, Родители: ??? и ???, Дети нет");} + public void RabbitInfo(string Name, List Child) + {Console.Write($"Кролик {Name}, Родители: ??? и ???, Детей: ");foreach(var i in Child){Console.WriteLine($"{i} ");} } } } \ No newline at end of file From e24d1dab5c782aafddea46bb4f1247943c92816f Mon Sep 17 00:00:00 2001 From: User Date: Mon, 3 Dec 2018 14:16:06 +0300 Subject: [PATCH 13/24] lab_4_7 --- CourseApp.Tests/UnitTest2.cs | 64 ++++++++++++++++++++---------------- CourseApp/Farm.cs | 7 ---- CourseApp/Menu.cs | 25 ++++++-------- CourseApp/Program.cs | 12 ++++--- CourseApp/map.cs | 16 --------- 5 files changed, 53 insertions(+), 71 deletions(-) delete mode 100644 CourseApp/map.cs diff --git a/CourseApp.Tests/UnitTest2.cs b/CourseApp.Tests/UnitTest2.cs index 59aa750..819f557 100644 --- a/CourseApp.Tests/UnitTest2.cs +++ b/CourseApp.Tests/UnitTest2.cs @@ -1,6 +1,7 @@ using System; using Xunit; using CourseApp; +using System.Collections.Generic; namespace CourseApp.Tests { @@ -9,41 +10,48 @@ public class UnitTest2 [Fact] public void Test1() { - Rabbit krosh = new Rabbit("momo","rad",3); - var name = krosh.name; - var color = krosh.color; - var age = krosh.age; - - Assert.Equal("momo",name); - Assert.Equal("rad",color); - Assert.Equal(3,age); + var krosh = new Rabbit(); + var N ="momo"; + krosh.RabbitInfo(N); + Assert.Equal("momo",N); } - [Fact] public void Test2() { - Rabbit krosh = new Rabbit("rar","grin",1); - var name = krosh.name; - var color = krosh.color; - var age = krosh.age; - - Assert.Equal("rar",name); - Assert.Equal("grin",color); - Assert.Equal(1,age); + var krosh = new Rabbit(); + var N ="momo"; + var P1 = "mu"; + var P2 = "nu"; + krosh.RabbitInfo(N); + Assert.Equal("momo",N); + Assert.Equal("mu",P1); + Assert.Equal("nu",P2); } - [Fact] public void Test3() { - Rabbit krosh = new Rabbit("ggwp","blue",9); - var name = krosh.name; - var color = krosh.color; - var age = krosh.age; - - Assert.Equal("ggwp",name); - Assert.Equal("blue",color); - Assert.Equal(9,age); - } - + var krosh = new Rabbit(); + var N ="momo"; + var P1 = "mu"; + var P2 = "nu"; + List ch=new List {"Mura","Gura","Fedya"}; + krosh.RabbitInfo(N,P1,P2,ch); + Assert.Equal("momo",N); + Assert.Equal("mu",P1); + Assert.Equal("nu",P2); + Assert.Equal("Mura",ch[0]); + Assert.Equal("Gura",ch[1]); + Assert.Equal("Fedya",ch[2]); + } + // На следующем тесте почему-то все зависает не понял пока почему... +/* [Fact] + public void Test4() + { + Menu ferma = new Menu(); + string go="Buy"; + ferma.Name = "Boo"; + ferma.menu(go); + Assert.Equal("Boo",ferma.klet[1]); + }*/ } } \ No newline at end of file diff --git a/CourseApp/Farm.cs b/CourseApp/Farm.cs index bb7176e..dc6466c 100644 --- a/CourseApp/Farm.cs +++ b/CourseApp/Farm.cs @@ -12,12 +12,5 @@ public class Farm public Farm() {} public Farm(string n) {this.Name=n;} public Farm(string n, string p1,string p2) {this.Name=n;this.Pearent1=p1;this.Pearent2=p2;} - public Farm(string n, string p1,string p2, List ch) - { - this.Name=n; - this.Pearent1=p1; - this.Pearent2=p2; - this.Child=ch; - } } } \ No newline at end of file diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index 5a48a98..3c8ec6c 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -6,18 +6,14 @@ namespace CourseApp { public class Menu { - public void menu() + public Rabbit info = new Rabbit(); + // public string go; + public string Name; + public string Pearent1; + public string Pearent2; + public ArrayList klet= new ArrayList(); + public void menu(string go) { - var info = new Rabbit(); - string go; - string Name; - string Pearent1; - string Pearent2; - ArrayList klet= new ArrayList(); - - Console.WriteLine ("Добро пожаловать на кроличью ферму!"); - do { - go = Console.ReadLine(); switch (go) { case "help": @@ -69,13 +65,12 @@ public void menu() {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2,i.Child);} }} Console.WriteLine("----------"); - } - break; + + break;} default: if(go != "Stop") { Console.WriteLine("Такой команды не существует. help - узнать список команд.");} break; - }} - while (go != "Stop"); + } } static void help() { diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 842a6b9..84dd8a9 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -30,12 +30,14 @@ static void Main() { Console.WriteLine (Fan(x,a,b)); } - + Console.WriteLine ("Кроличья ферма!"); - - Menu start = new Menu(); - start.menu(); - + string go; + Menu start = new Menu(); + do{ + go=Console.ReadLine(); + start.menu(go); + }while(go!="Stop"); } public static double Fan(double x, double a, double b) diff --git a/CourseApp/map.cs b/CourseApp/map.cs deleted file mode 100644 index 9483c7a..0000000 --- a/CourseApp/map.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace CourseApp -{ - public class map - { - - public string Name; - public map() {} - public map(string krolik) - { - Name = krolik; - - } - } -} \ No newline at end of file From 9e2749482ebb770d2478599e687fcad3e6e9bbab Mon Sep 17 00:00:00 2001 From: User Date: Tue, 4 Dec 2018 11:28:59 +0300 Subject: [PATCH 14/24] lab_4_8 --- CourseApp.Tests/UnitTest2.cs | 17 +++++++----- CourseApp/Farm.cs | 8 +++--- CourseApp/Menu.cs | 52 +++++++++++++++++------------------- CourseApp/Program.cs | 36 ++++++++++--------------- CourseApp/RabbitInfo.cs | 2 +- 5 files changed, 56 insertions(+), 59 deletions(-) diff --git a/CourseApp.Tests/UnitTest2.cs b/CourseApp.Tests/UnitTest2.cs index 819f557..a77a6e1 100644 --- a/CourseApp.Tests/UnitTest2.cs +++ b/CourseApp.Tests/UnitTest2.cs @@ -2,6 +2,7 @@ using Xunit; using CourseApp; using System.Collections.Generic; +using System.Collections; namespace CourseApp.Tests { @@ -43,15 +44,19 @@ public void Test3() Assert.Equal("Gura",ch[1]); Assert.Equal("Fedya",ch[2]); } - // На следующем тесте почему-то все зависает не понял пока почему... -/* [Fact] + [Fact] public void Test4() { Menu ferma = new Menu(); - string go="Buy"; ferma.Name = "Boo"; - ferma.menu(go); - Assert.Equal("Boo",ferma.klet[1]); - }*/ + Assert.Equal("Boo",ferma.Name); + } [Fact] + //следующий тест не рабочий + public void Test5() + { + Menu ferma = new Menu(); + ferma.klet.Add("Boo"); + Assert.Equal("Boo",ferma.klet[0]); + } } } \ No newline at end of file diff --git a/CourseApp/Farm.cs b/CourseApp/Farm.cs index dc6466c..711cec6 100644 --- a/CourseApp/Farm.cs +++ b/CourseApp/Farm.cs @@ -5,10 +5,12 @@ namespace CourseApp { public class Farm { - public string Name; - public string Pearent1; - public string Pearent2; public List Child=new List(); + public string Name{get;set;} + public string Pearent1 {get;set;} + private string pearent2{get;set;} + public string Pearent2 {get;set;} + public Farm() {} public Farm(string n) {this.Name=n;} public Farm(string n, string p1,string p2) {this.Name=n;this.Pearent1=p1;this.Pearent2=p2;} diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index 3c8ec6c..27f23cc 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -7,10 +7,9 @@ namespace CourseApp public class Menu { public Rabbit info = new Rabbit(); - // public string go; - public string Name; - public string Pearent1; - public string Pearent2; + public string Name {get;set;} + public string Pearent1{get;set;} + public string Pearent2{get;set;} public ArrayList klet= new ArrayList(); public void menu(string go) { @@ -18,13 +17,11 @@ public void menu(string go) { case "help": help(); - Console.WriteLine("----------"); break; case "Buy": Console.Write("Введите имя купленного кролика: "); Name = Console.ReadLine(); klet.Add(new Farm(Name)); - Console.WriteLine("----------"); break; case "Sel": Console.Write ("Введите имя новорожденного кролика: "); @@ -37,40 +34,41 @@ public void menu(string go) { if(Pearent1==i.Name||Pearent2==i.Name){i.Child.Add(Name);}; } - Console.WriteLine("----------"); break; case "Art": art(); - Console.WriteLine("----------"); break; case "Info": int num=1; foreach(Farm i in klet) { - Console.WriteLine($"{num++}) {i.Name}"); + Console.WriteLine($"{num++}) {i.Name}"); } - Console.WriteLine("----------"); break; case "Inf": - { Console.Write("Введите имя кролика о котором хотите унать: "); - Name = Console.ReadLine(); - foreach(Farm i in klet) - {if(i.Name==Name){ - if (i.Pearent1 == null && i.Child.Count == 0) - {info.RabbitInfo(i.Name);} - else if(i.Pearent1 != null && i.Child.Count == 0) - {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2);} - else if(i.Pearent1 == null && i.Child.Count != 0) - {info.RabbitInfo(i.Name,i.Child);} - else if(i.Pearent1 != null && i.Child.Count != 0) - {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2,i.Child);} - }} - Console.WriteLine("----------"); - - break;} + { + Console.Write("Введите имя кролика о котором хотите унать: "); + Name = Console.ReadLine(); + foreach(Farm i in klet) + { + if(i.Name==Name) + { + if (i.Pearent1 == null && i.Child.Count == 0) + {info.RabbitInfo(i.Name);} + else if(i.Pearent1 != null && i.Child.Count == 0) + {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2);} + else if(i.Pearent1 == null && i.Child.Count != 0) + {info.RabbitInfo(i.Name,i.Child);} + else if(i.Pearent1 != null && i.Child.Count != 0) + {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2,i.Child);} + } + } + } + break; default: if(go != "Stop") { Console.WriteLine("Такой команды не существует. help - узнать список команд.");} break; - } + } + Console.WriteLine("----------"); } static void help() { diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 84dd8a9..4b83909 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -5,48 +5,40 @@ namespace CourseApp public class Program { - static void Main() - { - + static void Main() + { Console.WriteLine("Волошин Константин"); - double a = 1.2; double b = 0.48; double xn = 0.7; double xk = 2.2; double dx = 0.3; double[] xx = {0.25, 0.36, 0.56, 0.94, 1.28}; - Console.WriteLine ("Задание А"); - for( double x=xn; x Child) - {Console.Write($"Кролик {Name}, Родители: ??? и ???, Детей: ");foreach(var i in Child){Console.WriteLine($"{i} ");} } + {Console.Write($"Кролик {Name}, Родители: ??? и ???, Дети: ");foreach(var i in Child){Console.WriteLine($"{i} ");} } } } \ No newline at end of file From 3390c5961167fde2eeda51de0624e608e17d792b Mon Sep 17 00:00:00 2001 From: User Date: Fri, 7 Dec 2018 19:20:49 +0300 Subject: [PATCH 15/24] lab_4_9 --- CourseApp.Tests/UnitTest2.cs | 14 ++++++++++++-- CourseApp/Farm.cs | 1 - CourseApp/Menu.cs | 5 +---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CourseApp.Tests/UnitTest2.cs b/CourseApp.Tests/UnitTest2.cs index a77a6e1..7172003 100644 --- a/CourseApp.Tests/UnitTest2.cs +++ b/CourseApp.Tests/UnitTest2.cs @@ -50,13 +50,23 @@ public void Test4() Menu ferma = new Menu(); ferma.Name = "Boo"; Assert.Equal("Boo",ferma.Name); - } [Fact] - //следующий тест не рабочий + } [Fact] public void Test5() { Menu ferma = new Menu(); ferma.klet.Add("Boo"); Assert.Equal("Boo",ferma.klet[0]); } + public void Test6() + { + Menu ferma = new Menu(); + ferma.menu("Stl"); + ferma.Name="Boo"; + ferma.Pearent1="Buu"; + ferma.Pearent2="Buuu"; + Assert.Equal("Boo",ferma.klet[0]); + Assert.Equal("Buu",ferma.klet[0]); + Assert.Equal("Buuu",ferma.klet[0]); + } } } \ No newline at end of file diff --git a/CourseApp/Farm.cs b/CourseApp/Farm.cs index 711cec6..ef37d66 100644 --- a/CourseApp/Farm.cs +++ b/CourseApp/Farm.cs @@ -8,7 +8,6 @@ public class Farm public List Child=new List(); public string Name{get;set;} public string Pearent1 {get;set;} - private string pearent2{get;set;} public string Pearent2 {get;set;} public Farm() {} diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index 27f23cc..470a4ea 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -4,12 +4,9 @@ namespace CourseApp { - public class Menu + public class Menu:Farm { public Rabbit info = new Rabbit(); - public string Name {get;set;} - public string Pearent1{get;set;} - public string Pearent2{get;set;} public ArrayList klet= new ArrayList(); public void menu(string go) { From 9969670dd4b2216a54fb1b08f0256eef8f0799f0 Mon Sep 17 00:00:00 2001 From: jskonst Date: Sun, 9 Dec 2018 21:57:24 +0300 Subject: [PATCH 16/24] Added stylecop for project --- CourseApp/CourseApp.csproj | 15 +++++++++++++++ CourseApp/Program.cs | 5 +++-- stylecop.json | 15 +++++++++++++++ stylecop.ruleset | 21 +++++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 stylecop.json create mode 100644 stylecop.ruleset diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 23df604..7afbee9 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -3,6 +3,21 @@ Exe netcoreapp2.1 + True + 1573,1591,1701;1702;1705 + + + + + + ../stylecop.ruleset + true + + + + + + diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 3f81738..248bbe4 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -2,11 +2,12 @@ namespace CourseApp { - class Program + public class Program { - static void Main(string[] args) + public static void Main(string[] args) { Console.WriteLine("Hello World!"); + Console.ReadLine(); } } } diff --git a/stylecop.json b/stylecop.json new file mode 100644 index 0000000..643b8c1 --- /dev/null +++ b/stylecop.json @@ -0,0 +1,15 @@ +{ + "$schema": + "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "documentExposedElements": false, + "documentInterfaces": false, + "companyName": "Test Company", + "copyrightText": + "This source code is Copyright © {companyName} and MAY NOT be copied, reproduced,\npublished, distributed or transmitted to or stored in any manner without prior\nwritten consent from {companyName} (www.yourcompany.com).", + "xmlHeader": false + } + }, + "additionalArguments": ["./stylecop.ruleset", "./stylecop.json"] +} diff --git a/stylecop.ruleset b/stylecop.ruleset new file mode 100644 index 0000000..b36938e --- /dev/null +++ b/stylecop.ruleset @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From c4a7f5d3aa7f62afd675dbc5c4fb29d24362f97e Mon Sep 17 00:00:00 2001 From: jskonst Date: Tue, 11 Dec 2018 11:21:14 +0300 Subject: [PATCH 17/24] Added stylecop for project --- CourseApp.Tests/CourseApp.Tests.csproj | 30 +++++++++++++++++++ CourseApp.Tests/DemoTest.cs | 14 +++++++++ CourseApp/CourseApp.csproj | 6 ++-- stylecop.json => stylecop/stylecop.json | 0 stylecop.ruleset => stylecop/stylecop.ruleset | 1 + 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 CourseApp.Tests/CourseApp.Tests.csproj create mode 100644 CourseApp.Tests/DemoTest.cs rename stylecop.json => stylecop/stylecop.json (100%) rename stylecop.ruleset => stylecop/stylecop.ruleset (95%) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj new file mode 100644 index 0000000..dcfd1f9 --- /dev/null +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp2.2 + True + 1573,1591,1701;1702;1705 + false + + + + + + + + + + + + + + + ../stylecop/stylecop.ruleset + true + + + + + + + diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs new file mode 100644 index 0000000..09e415e --- /dev/null +++ b/CourseApp.Tests/DemoTest.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class DemoTest + { + [Fact] + public void Test1() + { + Assert.True(true); + } + } +} diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 7afbee9..cc0df39 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -8,16 +8,16 @@ - + - ../stylecop.ruleset + ../stylecop/stylecop.ruleset true - + diff --git a/stylecop.json b/stylecop/stylecop.json similarity index 100% rename from stylecop.json rename to stylecop/stylecop.json diff --git a/stylecop.ruleset b/stylecop/stylecop.ruleset similarity index 95% rename from stylecop.ruleset rename to stylecop/stylecop.ruleset index b36938e..3350d0e 100644 --- a/stylecop.ruleset +++ b/stylecop/stylecop.ruleset @@ -15,6 +15,7 @@ + From a863fda18680d6a883b626e7f194592a03fa041a Mon Sep 17 00:00:00 2001 From: User Date: Tue, 11 Dec 2018 12:19:24 +0300 Subject: [PATCH 18/24] lab_4_10 --- CourseApp.Tests/UnitTest2.cs | 6 +++--- CourseApp/Farm.cs | 7 ++++++- CourseApp/Menu.cs | 18 +++++++++++++----- CourseApp/RabbitInfo.cs | 28 +++++++++++++++++++++++----- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/CourseApp.Tests/UnitTest2.cs b/CourseApp.Tests/UnitTest2.cs index 7172003..46f4636 100644 --- a/CourseApp.Tests/UnitTest2.cs +++ b/CourseApp.Tests/UnitTest2.cs @@ -11,7 +11,7 @@ public class UnitTest2 [Fact] public void Test1() { - var krosh = new Rabbit(); + var krosh = new InfoRabbit(); var N ="momo"; krosh.RabbitInfo(N); Assert.Equal("momo",N); @@ -19,7 +19,7 @@ public void Test1() [Fact] public void Test2() { - var krosh = new Rabbit(); + var krosh = new InfoRabbit(); var N ="momo"; var P1 = "mu"; var P2 = "nu"; @@ -31,7 +31,7 @@ public void Test2() [Fact] public void Test3() { - var krosh = new Rabbit(); + var krosh = new InfoRabbit(); var N ="momo"; var P1 = "mu"; var P2 = "nu"; diff --git a/CourseApp/Farm.cs b/CourseApp/Farm.cs index ef37d66..1656bf9 100644 --- a/CourseApp/Farm.cs +++ b/CourseApp/Farm.cs @@ -12,6 +12,11 @@ public class Farm public Farm() {} public Farm(string n) {this.Name=n;} - public Farm(string n, string p1,string p2) {this.Name=n;this.Pearent1=p1;this.Pearent2=p2;} + public Farm(string n, string p1,string p2) + { + this.Name=n; + this.Pearent1=p1; + this.Pearent2=p2; + } } } \ No newline at end of file diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index 470a4ea..fc01e36 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -6,7 +6,7 @@ namespace CourseApp { public class Menu:Farm { - public Rabbit info = new Rabbit(); + public InfoRabbit info = new InfoRabbit(); public ArrayList klet= new ArrayList(); public void menu(string go) { @@ -50,13 +50,21 @@ public void menu(string go) if(i.Name==Name) { if (i.Pearent1 == null && i.Child.Count == 0) - {info.RabbitInfo(i.Name);} + { + info.RabbitInfo(i.Name); + } else if(i.Pearent1 != null && i.Child.Count == 0) - {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2);} + { + info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2); + } else if(i.Pearent1 == null && i.Child.Count != 0) - {info.RabbitInfo(i.Name,i.Child);} + { + info.RabbitInfo(i.Name,i.Child); + } else if(i.Pearent1 != null && i.Child.Count != 0) - {info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2,i.Child);} + { + info.RabbitInfo(i.Name,i.Pearent1,i.Pearent2,i.Child); + } } } } diff --git a/CourseApp/RabbitInfo.cs b/CourseApp/RabbitInfo.cs index d262f66..4d01a6d 100644 --- a/CourseApp/RabbitInfo.cs +++ b/CourseApp/RabbitInfo.cs @@ -3,13 +3,31 @@ namespace CourseApp { - public class Rabbit + public class InfoRabbit { public void RabbitInfo(string Name, string Pearent1,string Pearent2, List Child) - {Console.Write($"Кролик {Name}, Родители: {Pearent1} и {Pearent2}, Дети: ");foreach(var i in Child){Console.WriteLine($"{i} ");}} - public void RabbitInfo(string Name, string Pearent1,string Pearent2) {Console.WriteLine($"Кролик {Name}, Родители: {Pearent1} и {Pearent2}, Детей нет");} - public void RabbitInfo(string Name) {Console.WriteLine($"Кролик {Name}, Родители: ??? и ???, Дети нет");} + { + Console.Write($"Кролик {Name}, Родители: {Pearent1} и {Pearent2}, Дети: "); + foreach(var i in Child) + { + Console.WriteLine($"{i} "); + } + } + public void RabbitInfo(string Name, string Pearent1,string Pearent2) + { + Console.WriteLine($"Кролик {Name}, Родители: {Pearent1} и {Pearent2}, Детей нет"); + } + public void RabbitInfo(string Name) + { + Console.WriteLine($"Кролик {Name}, Родители: ??? и ???, Дети нет"); + } public void RabbitInfo(string Name, List Child) - {Console.Write($"Кролик {Name}, Родители: ??? и ???, Дети: ");foreach(var i in Child){Console.WriteLine($"{i} ");} } + { + Console.Write($"Кролик {Name}, Родители: ??? и ???, Дети: "); + foreach(var i in Child) + { + Console.WriteLine($"{i} "); + } + } } } \ No newline at end of file From 2a6774deaecb34da67f736806b6b0b18d8ef628b Mon Sep 17 00:00:00 2001 From: User Date: Sat, 15 Dec 2018 21:00:50 +0300 Subject: [PATCH 19/24] lab_4_11_slom --- CourseApp/Info.cs | 16 ++++++++-------- CourseApp/Krolik.cs | 28 ---------------------------- CourseApp/Menu.cs | 39 ++++++++++++++++++++++++++++++++++++++- CourseApp/Zoo.cs | 7 +++++++ 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/CourseApp/Info.cs b/CourseApp/Info.cs index 1e74c6f..8cec67e 100644 --- a/CourseApp/Info.cs +++ b/CourseApp/Info.cs @@ -5,28 +5,28 @@ namespace CourseApp { public class Info { - public void PetInfo(string name, string pearent1, string pearent2, List child) + public void PetInfo(string name, string pearent1, string pearent2, List child, string vid) { - Console.Write($"Кролик {name}, Родители: {pearent1} и {pearent2}, Дети: "); + Console.Write($"{vid} {name}, Родители: {pearent1} и {pearent2}, Дети: "); foreach(var i in child) { Console.WriteLine($"{i} "); } } - public void PetInfo(string name, string pearent1, string pearent2) + public void PetInfo(string name, string pearent1, string pearent2, string vid) { - Console.WriteLine($"Кролик {name}, Родители: {pearent1} и {pearent2}, Детей нет"); + Console.WriteLine($"{vid} {name}, Родители: {pearent1} и {pearent2}, Детей нет"); } - public void PetInfo(string name) + public void PetInfo(string name, string vid) { - Console.WriteLine($"Кролик {name}, Родители: ??? и ???, Дети нет"); + Console.WriteLine($"{vid} {name}, Родители: ??? и ???, Дети нет"); } - public void PetInfo(string name, List child) + public void PetInfo(string name, List child, string vid) { - Console.Write($"Кролик {name}, Родители: ??? и ???, Дети: "); + Console.Write($"{vid} {name}, Родители: ??? и ???, Дети: "); foreach(var i in child) { Console.WriteLine($"{i} "); diff --git a/CourseApp/Krolik.cs b/CourseApp/Krolik.cs index 9051317..ca44442 100644 --- a/CourseApp/Krolik.cs +++ b/CourseApp/Krolik.cs @@ -29,33 +29,5 @@ public void NewKrolik() } } } - - public void RebbitInfo() - { - Console.Write("Введите имя кролика о котором хотите унать: "); - Name = Console.ReadLine(); - foreach(NewPet i in Klet) - { - if(i.Name == Name) - { - if (i.Pearent1 == null && i.Child.Count == 0) - { - PInfo.PetInfo(i.Name); - } - else if(i.Pearent1 != null && i.Child.Count == 0) - { - PInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2); - } - else if(i.Pearent1 == null && i.Child.Count != 0) - { - PInfo.PetInfo(i.Name, i.Child); - } - else if(i.Pearent1 != null && i.Child.Count != 0) - { - PInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Child); - } - } - } - } } } \ No newline at end of file diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index f130583..65b77d9 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -8,18 +8,55 @@ public class Menu : Zoo { public void MenuZoo(string go) { + Krolik krosh = new Krolik(); switch (go) { case "Buy": + Console.WriteLine("Введите кого вы хоите купить: кролик/мышь"); + Vid = Console.ReadLine(); + if (Vid == "кролик") + { + krosh.BuyKrolik(); + } break; case "Sel": + Console.WriteLine("Введите кого вы хоите разводить: кролик/мышь"); + Vid = Console.ReadLine(); + if (Vid == "кролик") + { + krosh.NewKrolik(); + } break; case "Art": Art(); break; case "Inf": + Console.Write("Введите имя животного о котором хотите унать: "); + Name = Console.ReadLine(); + foreach(NewPet i in Klet) + { + if(i.Name == Name) + { + if (i.Pearent1 == null && i.Child.Count == 0) + { + PInfo.PetInfo(i.Name, i.Vid); + } + else if(i.Pearent1 != null && i.Child.Count == 0) + { + PInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Vid); + } + else if(i.Pearent1 == null && i.Child.Count != 0) + { + PInfo.PetInfo(i.Name, i.Child, i.Vid); + } + else if(i.Pearent1 != null && i.Child.Count != 0) + { + PInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Child, i.Vid); + } + } + } break; case "help": @@ -28,7 +65,7 @@ public void MenuZoo(string go) case "Info": int num = 1; foreach(NewPet i in Klet) { - Console.WriteLine($"{num++}) {i.Name}"); + Console.WriteLine($"{num++}){i.Vid} {i.Name}"); } break; diff --git a/CourseApp/Zoo.cs b/CourseApp/Zoo.cs index 93fb47b..feb0ca4 100644 --- a/CourseApp/Zoo.cs +++ b/CourseApp/Zoo.cs @@ -10,10 +10,17 @@ public class Zoo public ArrayList Klet = new ArrayList(); public List Child = new List(); + public string Vid {get; set; } + public string Name {get; set; } public string Pearent1 {get; set; } public string Pearent2 {get; set; } + + /* public override string ToString() + { + return $"{Vid}: " + Name; + }*/ } } \ No newline at end of file From 69539c15a3214247e9a6a5d34cbc96c7fb10cd6e Mon Sep 17 00:00:00 2001 From: User Date: Sat, 15 Dec 2018 22:17:01 +0300 Subject: [PATCH 20/24] lab_4_11M --- CourseApp/Menu.cs | 9 +++++---- CourseApp/NewPet.cs | 2 +- CourseApp/Zoo.cs | 26 +++++++++++++++++++------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index 65b77d9..e3a6075 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -8,6 +8,7 @@ public class Menu : Zoo { public void MenuZoo(string go) { + Info pInfo = new Info(); Krolik krosh = new Krolik(); switch (go) { @@ -41,19 +42,19 @@ public void MenuZoo(string go) { if (i.Pearent1 == null && i.Child.Count == 0) { - PInfo.PetInfo(i.Name, i.Vid); + pInfo.PetInfo(i.Name, i.Vid); } else if(i.Pearent1 != null && i.Child.Count == 0) { - PInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Vid); + pInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Vid); } else if(i.Pearent1 == null && i.Child.Count != 0) { - PInfo.PetInfo(i.Name, i.Child, i.Vid); + pInfo.PetInfo(i.Name, i.Child, i.Vid); } else if(i.Pearent1 != null && i.Child.Count != 0) { - PInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Child, i.Vid); + pInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Child, i.Vid); } } } diff --git a/CourseApp/NewPet.cs b/CourseApp/NewPet.cs index 8a86fc0..36406dc 100644 --- a/CourseApp/NewPet.cs +++ b/CourseApp/NewPet.cs @@ -4,7 +4,7 @@ namespace CourseApp { - public class NewPet : Zoo + public class NewPet : Krolik { public NewPet(string n) { diff --git a/CourseApp/Zoo.cs b/CourseApp/Zoo.cs index feb0ca4..0ec5fad 100644 --- a/CourseApp/Zoo.cs +++ b/CourseApp/Zoo.cs @@ -6,21 +6,33 @@ namespace CourseApp { public class Zoo { - public Info PInfo = new Info(); public ArrayList Klet = new ArrayList(); public List Child = new List(); public string Vid {get; set; } - public string Name {get; set; } + public string Name + { + get + { + return Name; + } + + set + { + foreach(NewPet i in Klet) + { + if(i.Name == Name) + { + Console.Write("Такое имя уже существует, введите другое имя:"); + Name = Console.ReadLine(); + } + } + } + } public string Pearent1 {get; set; } public string Pearent2 {get; set; } - - /* public override string ToString() - { - return $"{Vid}: " + Name; - }*/ } } \ No newline at end of file From 09cd8fff15f9ad8eeb50168aba797a7dbdbb4d9f Mon Sep 17 00:00:00 2001 From: User Date: Tue, 18 Dec 2018 12:54:49 +0300 Subject: [PATCH 21/24] lab_5_1 --- CourseApp/Krolik.cs | 17 +++++++++++------ CourseApp/Menu.cs | 34 ++++++++++++++++++++-------------- CourseApp/NewPet.cs | 16 +++++++++++----- CourseApp/Pet.cs | 27 +++++++++++++++++++++++++++ CourseApp/Program.cs | 2 +- CourseApp/Zoo.cs | 38 -------------------------------------- 6 files changed, 70 insertions(+), 64 deletions(-) create mode 100644 CourseApp/Pet.cs delete mode 100644 CourseApp/Zoo.cs diff --git a/CourseApp/Krolik.cs b/CourseApp/Krolik.cs index ca44442..4f389fb 100644 --- a/CourseApp/Krolik.cs +++ b/CourseApp/Krolik.cs @@ -4,13 +4,13 @@ namespace CourseApp { - public class Krolik : Zoo + public class Krolik : Pet { public void BuyKrolik() { Console.Write("Введите имя купленного кролика: "); Name = Console.ReadLine(); - Klet.Add(new NewPet(Name)); + Spisok.Add(Name, new NewPet(Vid)); } public void NewKrolik() @@ -20,12 +20,17 @@ public void NewKrolik() Console.WriteLine("Введите имена родителй кролика: "); Pearent1 = Console.ReadLine(); Pearent2 = Console.ReadLine(); - Klet.Add(new NewPet(Name, Pearent1, Pearent2)); - foreach(NewPet i in Klet) + Spisok.Add(Name, new NewPet(Pearent1, Pearent2, "кролик")); + foreach(string i in Spisok.Keys) { - if(Pearent1 == i.Name || Pearent2 == i.Name) + if(Pearent1 == i ) { - i.Child.Add(Name); + Spisok.Add(Pearent1, new NewPet(Name)); + } + + if(Pearent2 == i) + { + Spisok.Add(Pearent2, new NewPet(Name)); } } } diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index e3a6075..2f9e497 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -4,20 +4,20 @@ namespace CourseApp { - public class Menu : Zoo + public class Menu : Pet { - public void MenuZoo(string go) + public void MenuPets(string go) { - Info pInfo = new Info(); Krolik krosh = new Krolik(); - switch (go) + Info pInfo = new Info(); + switch(go) { case "Buy": Console.WriteLine("Введите кого вы хоите купить: кролик/мышь"); Vid = Console.ReadLine(); if (Vid == "кролик") { - krosh.BuyKrolik(); + krosh.BuyKrolik(); } break; @@ -36,37 +36,43 @@ public void MenuZoo(string go) case "Inf": Console.Write("Введите имя животного о котором хотите унать: "); Name = Console.ReadLine(); - foreach(NewPet i in Klet) + foreach(string j in Spisok.Keys) { - if(i.Name == Name) + foreach(NewPet i in Spisok.Values) + { + if(j == Name) { if (i.Pearent1 == null && i.Child.Count == 0) { - pInfo.PetInfo(i.Name, i.Vid); + pInfo.PetInfo(j, i.Vid); } else if(i.Pearent1 != null && i.Child.Count == 0) { - pInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Vid); + pInfo.PetInfo(j, i.Pearent1, i.Pearent2, i.Vid); } else if(i.Pearent1 == null && i.Child.Count != 0) { - pInfo.PetInfo(i.Name, i.Child, i.Vid); + pInfo.PetInfo(j, i.Child, i.Vid); } else if(i.Pearent1 != null && i.Child.Count != 0) { - pInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Child, i.Vid); + pInfo.PetInfo(j, i.Pearent1, i.Pearent2, i.Child, i.Vid); } } } + } break; case "help": Help(); break; - case "Info": int num = 1; - foreach(NewPet i in Klet) + case "Info": + foreach(string i in Spisok.Keys) { - Console.WriteLine($"{num++}){i.Vid} {i.Name}"); + foreach (NewPet j in Spisok.Values) + { + Console.WriteLine($"{Kol++}){j.Vid} {i}"); + } } break; diff --git a/CourseApp/NewPet.cs b/CourseApp/NewPet.cs index 36406dc..dcbcb59 100644 --- a/CourseApp/NewPet.cs +++ b/CourseApp/NewPet.cs @@ -4,18 +4,24 @@ namespace CourseApp { - public class NewPet : Krolik + public class NewPet : Pet { - public NewPet(string n) + public NewPet(string v) { - this.Name = n; + this.Vid = v; } - public NewPet(string n, string p1, string p2) + public NewPet(string p1, string p2, string v) { - this.Name = n; this.Pearent1 = p1; this.Pearent2 = p2; + this.Vid = v; + } + + public NewPet(string child, string v) + { + this.Child.Add(child); + this.Vid = v; } } } \ No newline at end of file diff --git a/CourseApp/Pet.cs b/CourseApp/Pet.cs new file mode 100644 index 0000000..9f75ecf --- /dev/null +++ b/CourseApp/Pet.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace CourseApp +{ + public abstract class Pet + { + private Dictionary spisok = new Dictionary(); + + private List child = new List(); + + public Dictionary Spisok { get => spisok; set => spisok = value; } + + public List Child { get => child; set => child = value; } + + public string Vid {get; set; } + + public string Name {get; set; } + + public string Pearent1 {get; set; } + + public string Pearent2 {get; set; } + + public int Kol {get; set; } + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 0f2f9bb..792502b 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -33,7 +33,7 @@ public static void Main() do { go = Console.ReadLine(); - start.MenuZoo(go); + start.MenuPets(go); } while(go != "Stop"); } diff --git a/CourseApp/Zoo.cs b/CourseApp/Zoo.cs deleted file mode 100644 index 0ec5fad..0000000 --- a/CourseApp/Zoo.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace CourseApp -{ - public class Zoo - { - public ArrayList Klet = new ArrayList(); - public List Child = new List(); - - public string Vid {get; set; } - - public string Name - { - get - { - return Name; - } - - set - { - foreach(NewPet i in Klet) - { - if(i.Name == Name) - { - Console.Write("Такое имя уже существует, введите другое имя:"); - Name = Console.ReadLine(); - } - } - } - } - - public string Pearent1 {get; set; } - - public string Pearent2 {get; set; } - } -} \ No newline at end of file From 2056920a3f1861e9dea8c4cb5501ee898ccbcfb6 Mon Sep 17 00:00:00 2001 From: User Date: Sun, 23 Dec 2018 15:12:49 +0300 Subject: [PATCH 22/24] lab_5_2 --- CourseApp/AbstractPet.cs | 13 ++++++ CourseApp/Cavy.cs | 43 ++++++++++++++++++++ CourseApp/Info.cs | 36 ----------------- CourseApp/Krolik.cs | 19 +++++---- CourseApp/Menu.cs | 86 +++++++++++++++++++++------------------- CourseApp/NewPet.cs | 20 ++++++++++ CourseApp/Pet.cs | 4 +- 7 files changed, 134 insertions(+), 87 deletions(-) create mode 100644 CourseApp/AbstractPet.cs create mode 100644 CourseApp/Cavy.cs delete mode 100644 CourseApp/Info.cs diff --git a/CourseApp/AbstractPet.cs b/CourseApp/AbstractPet.cs new file mode 100644 index 0000000..bf8d5c2 --- /dev/null +++ b/CourseApp/AbstractPet.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace CourseApp +{ + public abstract class AbstractPet : Pet + { + public abstract void BuyPet(); + + public abstract void NewPet(); + } +} \ No newline at end of file diff --git a/CourseApp/Cavy.cs b/CourseApp/Cavy.cs new file mode 100644 index 0000000..9c83998 --- /dev/null +++ b/CourseApp/Cavy.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace CourseApp +{ + public class Cavy : AbstractPet + { + public override void BuyPet() + { + Console.Write("Введите имя купленной морской свинки: "); + Name = Console.ReadLine(); + Spisok.Add(Name, new NewPet("cavy")); + } + + public override void NewPet() + { + Console.Write("Введите имя новорожденной морской свинки: "); + Name = Console.ReadLine(); + Console.WriteLine("Введите имена родителй морской свинки: "); + Pearent1 = Console.ReadLine(); + Pearent2 = Console.ReadLine(); + Spisok.Add(Name, new NewPet(Pearent1, Pearent2, "cavy")); + foreach(string i in Spisok.Keys) + { + if(Pearent1 == i ) + { + Spisok.Add(Pearent1, new NewPet(Name, "cavy")); + } + + if(Pearent2 == i) + { + Spisok.Add(Pearent2, new NewPet(Name, "cavy")); + } + } + } + + public override string ToString() + { + return $"Морская свинка: {Name} "; + } + } +} \ No newline at end of file diff --git a/CourseApp/Info.cs b/CourseApp/Info.cs deleted file mode 100644 index 8cec67e..0000000 --- a/CourseApp/Info.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace CourseApp -{ - public class Info - { - public void PetInfo(string name, string pearent1, string pearent2, List child, string vid) - { - Console.Write($"{vid} {name}, Родители: {pearent1} и {pearent2}, Дети: "); - foreach(var i in child) - { - Console.WriteLine($"{i} "); - } - } - - public void PetInfo(string name, string pearent1, string pearent2, string vid) - { - Console.WriteLine($"{vid} {name}, Родители: {pearent1} и {pearent2}, Детей нет"); - } - - public void PetInfo(string name, string vid) - { - Console.WriteLine($"{vid} {name}, Родители: ??? и ???, Дети нет"); - } - - public void PetInfo(string name, List child, string vid) - { - Console.Write($"{vid} {name}, Родители: ??? и ???, Дети: "); - foreach(var i in child) - { - Console.WriteLine($"{i} "); - } - } - } -} \ No newline at end of file diff --git a/CourseApp/Krolik.cs b/CourseApp/Krolik.cs index 4f389fb..cd89bb5 100644 --- a/CourseApp/Krolik.cs +++ b/CourseApp/Krolik.cs @@ -4,35 +4,40 @@ namespace CourseApp { - public class Krolik : Pet + public class Krolik : AbstractPet { - public void BuyKrolik() + public override void BuyPet() { Console.Write("Введите имя купленного кролика: "); Name = Console.ReadLine(); - Spisok.Add(Name, new NewPet(Vid)); + Spisok.Add(Name, new NewPet("rabbit")); } - public void NewKrolik() + public override void NewPet() { Console.Write("Введите имя новорожденного кролика: "); Name = Console.ReadLine(); Console.WriteLine("Введите имена родителй кролика: "); Pearent1 = Console.ReadLine(); Pearent2 = Console.ReadLine(); - Spisok.Add(Name, new NewPet(Pearent1, Pearent2, "кролик")); + Spisok.Add(Name, new NewPet(Pearent1, Pearent2, "rabbit")); foreach(string i in Spisok.Keys) { if(Pearent1 == i ) { - Spisok.Add(Pearent1, new NewPet(Name)); + Spisok.Add(Pearent1, new NewPet(Name, "rabbit")); } if(Pearent2 == i) { - Spisok.Add(Pearent2, new NewPet(Name)); + Spisok.Add(Pearent2, new NewPet(Name, "rabbit")); } } } + + public override string ToString() + { + return $"Кролик: {Name} "; + } } } \ No newline at end of file diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index 2f9e497..ff57a58 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -6,27 +6,35 @@ namespace CourseApp { public class Menu : Pet { - public void MenuPets(string go) + public void MenuPets(string go) { Krolik krosh = new Krolik(); - Info pInfo = new Info(); + Cavy cavy = new Cavy(); switch(go) { case "Buy": - Console.WriteLine("Введите кого вы хоите купить: кролик/мышь"); + Console.WriteLine("Введите кого вы хоите купить: rabbit/cavy"); Vid = Console.ReadLine(); - if (Vid == "кролик") + if (Vid == "rabbit") { - krosh.BuyKrolik(); + krosh.BuyPet(); + } + else if (Vid == "Cavy") + { + cavy.BuyPet(); } break; case "Sel": - Console.WriteLine("Введите кого вы хоите разводить: кролик/мышь"); + Console.WriteLine("Введите кого вы хоите разводить: rabbit/cavy"); Vid = Console.ReadLine(); - if (Vid == "кролик") + if (Vid == "rabbit") { - krosh.NewKrolik(); + krosh.NewPet(); + } + else if (Vid == "Cavy") + { + cavy.NewPet(); } break; @@ -34,45 +42,23 @@ public void MenuPets(string go) Art(); break; case "Inf": + { + { Console.Write("Введите имя животного о котором хотите унать: "); Name = Console.ReadLine(); - foreach(string j in Spisok.Keys) - { - foreach(NewPet i in Spisok.Values) - { - if(j == Name) - { - if (i.Pearent1 == null && i.Child.Count == 0) - { - pInfo.PetInfo(j, i.Vid); - } - else if(i.Pearent1 != null && i.Child.Count == 0) - { - pInfo.PetInfo(j, i.Pearent1, i.Pearent2, i.Vid); - } - else if(i.Pearent1 == null && i.Child.Count != 0) - { - pInfo.PetInfo(j, i.Child, i.Vid); - } - else if(i.Pearent1 != null && i.Child.Count != 0) - { - pInfo.PetInfo(j, i.Pearent1, i.Pearent2, i.Child, i.Vid); - } - } - } - } + NewPet rrr = Spisok[Name]; + PetInfo(rrr, Name); + } + } break; case "help": Help(); break; - case "Info": - foreach(string i in Spisok.Keys) + case "Info": int kol = 1; + foreach(KeyValuePair i in Spisok) { - foreach (NewPet j in Spisok.Values) - { - Console.WriteLine($"{Kol++}){j.Vid} {i}"); - } + Console.WriteLine(kol++ + ") " + i.Value.Vid + " " + i.Key); } break; @@ -87,7 +73,7 @@ public void MenuPets(string go) Console.WriteLine("----------"); } - private static void Help() + private static void Help() { Console.WriteLine(@" Команды: @@ -100,12 +86,30 @@ private static void Help() "); } - private static void Art() + private static void Art() { Console.WriteLine(@" ------/)/)------/),/)----(\__/)---(\.(\-----(\(\ -----(':'=)----(':'=)---(=';'=)---(=':')----(=':') --(')('),,)-(')('),,)---(')_(')---(..(')(')-(..(')(') "); } + + private void PetInfo(NewPet i, string name) + { + Console.Write($"{i.Vid}) {name}"); + if (i.Pearent1 != null || i.Pearent2 != null) + { + Console.Write($", Родители: {i.Pearent1} и {i.Pearent2}"); + } + + if (Child != null) + { + Console.Write($", Дети: "); + foreach(var j in Child) + { + Console.WriteLine($"{j} "); + } + } + } } } \ No newline at end of file diff --git a/CourseApp/NewPet.cs b/CourseApp/NewPet.cs index dcbcb59..95970b8 100644 --- a/CourseApp/NewPet.cs +++ b/CourseApp/NewPet.cs @@ -23,5 +23,25 @@ public NewPet(string child, string v) this.Child.Add(child); this.Vid = v; } + + public override string ToString() + { + string tostr = $"{Vid} {Name}"; + if (Pearent1 != null || Pearent2 != null) + { + tostr += $", Родители: {Pearent1} и {Pearent2}"; + } + + if (Child != null) + { + tostr += $", Дети: "; + foreach(var j in Child) + { + tostr += $"{j} "; + } + } + + return tostr; + } } } \ No newline at end of file diff --git a/CourseApp/Pet.cs b/CourseApp/Pet.cs index 9f75ecf..9cb7e54 100644 --- a/CourseApp/Pet.cs +++ b/CourseApp/Pet.cs @@ -4,7 +4,7 @@ namespace CourseApp { - public abstract class Pet + public class Pet { private Dictionary spisok = new Dictionary(); @@ -21,7 +21,5 @@ public abstract class Pet public string Pearent1 {get; set; } public string Pearent2 {get; set; } - - public int Kol {get; set; } } } \ No newline at end of file From 76833e2812afff8af281ae8e155703ca1c200cfe Mon Sep 17 00:00:00 2001 From: jskonst Date: Sat, 29 Dec 2018 11:21:05 +0300 Subject: [PATCH 23/24] changed logic --- CourseApp/AbstractPet.cs | 13 ---- CourseApp/Cavy.cs | 11 +--- CourseApp/Krolik.cs | 10 +-- CourseApp/Menu.cs | 138 ++++++++++++++++----------------------- CourseApp/NewPet.cs | 47 ------------- CourseApp/Pet.cs | 48 +++++++++++--- CourseApp/PetStore.cs | 27 ++++++++ 7 files changed, 126 insertions(+), 168 deletions(-) delete mode 100644 CourseApp/AbstractPet.cs delete mode 100644 CourseApp/NewPet.cs create mode 100644 CourseApp/PetStore.cs diff --git a/CourseApp/AbstractPet.cs b/CourseApp/AbstractPet.cs deleted file mode 100644 index bf8d5c2..0000000 --- a/CourseApp/AbstractPet.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace CourseApp -{ - public abstract class AbstractPet : Pet - { - public abstract void BuyPet(); - - public abstract void NewPet(); - } -} \ No newline at end of file diff --git a/CourseApp/Cavy.cs b/CourseApp/Cavy.cs index 9c83998..9bc41de 100644 --- a/CourseApp/Cavy.cs +++ b/CourseApp/Cavy.cs @@ -4,15 +4,8 @@ namespace CourseApp { - public class Cavy : AbstractPet + public class Cavy : Pet { - public override void BuyPet() - { - Console.Write("Введите имя купленной морской свинки: "); - Name = Console.ReadLine(); - Spisok.Add(Name, new NewPet("cavy")); - } - public override void NewPet() { Console.Write("Введите имя новорожденной морской свинки: "); @@ -35,7 +28,7 @@ public override void NewPet() } } - public override string ToString() + public override string GetInfo() { return $"Морская свинка: {Name} "; } diff --git a/CourseApp/Krolik.cs b/CourseApp/Krolik.cs index cd89bb5..b223085 100644 --- a/CourseApp/Krolik.cs +++ b/CourseApp/Krolik.cs @@ -4,14 +4,8 @@ namespace CourseApp { - public class Krolik : AbstractPet + public class Krolik : Pet { - public override void BuyPet() - { - Console.Write("Введите имя купленного кролика: "); - Name = Console.ReadLine(); - Spisok.Add(Name, new NewPet("rabbit")); - } public override void NewPet() { @@ -35,7 +29,7 @@ public override void NewPet() } } - public override string ToString() + public override string GetInfo() { return $"Кролик: {Name} "; } diff --git a/CourseApp/Menu.cs b/CourseApp/Menu.cs index ff57a58..28601aa 100644 --- a/CourseApp/Menu.cs +++ b/CourseApp/Menu.cs @@ -4,78 +4,70 @@ namespace CourseApp { - public class Menu : Pet + public class Menu { - public void MenuPets(string go) - { - Krolik krosh = new Krolik(); - Cavy cavy = new Cavy(); - switch(go) - { - case "Buy": - Console.WriteLine("Введите кого вы хоите купить: rabbit/cavy"); - Vid = Console.ReadLine(); - if (Vid == "rabbit") - { - krosh.BuyPet(); - } - else if (Vid == "Cavy") - { - cavy.BuyPet(); - } - break; - case "Sel": - Console.WriteLine("Введите кого вы хоите разводить: rabbit/cavy"); - Vid = Console.ReadLine(); - if (Vid == "rabbit") - { - krosh.NewPet(); - } - else if (Vid == "Cavy") - { - cavy.NewPet(); - } - - break; - case "Art": - Art(); - break; - case "Inf": - { - { - Console.Write("Введите имя животного о котором хотите унать: "); - Name = Console.ReadLine(); - NewPet rrr = Spisok[Name]; - PetInfo(rrr, Name); - } - } + PetStore petStore; + public Menu() + { + this.petStore = new PetStore(); + } - break; - case "help": - Help(); - break; - case "Info": int kol = 1; - foreach(KeyValuePair i in Spisok) + public void MenuPets(string go) + { + switch (go) { - Console.WriteLine(kol++ + ") " + i.Value.Vid + " " + i.Key); - } + case "Buy": + Console.WriteLine("Введите кого вы хоите купить: rabbit/cavy"); + string type = Console.ReadLine(); + this.petStore.CreatePet(type); + break; + case "Sel": + Console.WriteLine("Введите кого вы хоите разводить: rabbit/cavy"); + string type = Console.ReadLine(); + this.petStore.CreatePet(type); - break; - default: if(go != "Stop") - { - Console.WriteLine("Такой команды не существует. help - узнать список команд."); - } + break; + case "Art": + Art(); + break; + case "Inf": + { + { + Console.Write("Введите имя животного о котором хотите унать: "); + Name = Console.ReadLine(); + NewPet rrr = Spisok[Name]; + PetInfo(rrr, Name); + } + } - break; - } + break; + case "help": + Help(); + break; + case "Info": + int kol = 1; + foreach (KeyValuePair i in Spisok) + { + Console.WriteLine(kol++ + ") " + i.Value.Vid + " " + i.Key); + } - Console.WriteLine("----------"); - } + break; + default: + if (go != "Stop") + { + Console.WriteLine("Такой команды не существует. help - узнать список команд."); + } - private static void Help() + break; + } + + Console.WriteLine("----------"); + } + + private static void Help() { - Console.WriteLine(@" + Console.WriteLine(@" Команды: Stop - закончить программу; Art - вывести рисунок кроликов; @@ -86,30 +78,12 @@ private static void Help() "); } - private static void Art() + private static void Art() { Console.WriteLine(@" ------/)/)------/),/)----(\__/)---(\.(\-----(\(\ -----(':'=)----(':'=)---(=';'=)---(=':')----(=':') --(')('),,)-(')('),,)---(')_(')---(..(')(')-(..(')(') "); } - - private void PetInfo(NewPet i, string name) - { - Console.Write($"{i.Vid}) {name}"); - if (i.Pearent1 != null || i.Pearent2 != null) - { - Console.Write($", Родители: {i.Pearent1} и {i.Pearent2}"); - } - - if (Child != null) - { - Console.Write($", Дети: "); - foreach(var j in Child) - { - Console.WriteLine($"{j} "); - } - } - } } } \ No newline at end of file diff --git a/CourseApp/NewPet.cs b/CourseApp/NewPet.cs deleted file mode 100644 index 95970b8..0000000 --- a/CourseApp/NewPet.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; - -namespace CourseApp -{ - public class NewPet : Pet - { - public NewPet(string v) - { - this.Vid = v; - } - - public NewPet(string p1, string p2, string v) - { - this.Pearent1 = p1; - this.Pearent2 = p2; - this.Vid = v; - } - - public NewPet(string child, string v) - { - this.Child.Add(child); - this.Vid = v; - } - - public override string ToString() - { - string tostr = $"{Vid} {Name}"; - if (Pearent1 != null || Pearent2 != null) - { - tostr += $", Родители: {Pearent1} и {Pearent2}"; - } - - if (Child != null) - { - tostr += $", Дети: "; - foreach(var j in Child) - { - tostr += $"{j} "; - } - } - - return tostr; - } - } -} \ No newline at end of file diff --git a/CourseApp/Pet.cs b/CourseApp/Pet.cs index 9cb7e54..27fc287 100644 --- a/CourseApp/Pet.cs +++ b/CourseApp/Pet.cs @@ -4,22 +4,52 @@ namespace CourseApp { - public class Pet + public abstract class Pet { - private Dictionary spisok = new Dictionary(); + public Pet() // Default constructor + :this("Noname") + { + } + + public Pet(string name) // Default constructor + :this(name, null, null) + { + } + + public Pet(string name, Pet parent1, Pet parent2) // Default constructor + { + this.Name = name; + this.Parent1 = parent1; + this.Parent2 = parent2; + } + public List Childs { get; set; } - private List child = new List(); + public string Name {get; set; } - public Dictionary Spisok { get => spisok; set => spisok = value; } + public Pet Parent1 {get; set; } - public List Child { get => child; set => child = value; } + public Pet Parent2 {get; set; } - public string Vid {get; set; } + public override string ToString() + { + string tostr = $"{GetInfo()} \r\n"; + if (Pearent1 != null || Pearent2 != null) + { + tostr += $", Родители: {Pearent1} и {Pearent2}"; + } - public string Name {get; set; } + if (Child != null) + { + tostr += $", Дети: "; + foreach (var j in Child) + { + tostr += $"{j} "; + } + } - public string Pearent1 {get; set; } + return tostr; + } - public string Pearent2 {get; set; } + public abstract string GetInfo(); } } \ No newline at end of file diff --git a/CourseApp/PetStore.cs b/CourseApp/PetStore.cs new file mode 100644 index 0000000..da36414 --- /dev/null +++ b/CourseApp/PetStore.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace CourseApp +{ + public class PetStore + { + public Pet CreatePet(string type) + { + if (type == "Rabbit") //use switch case instead + { + return new Krolik(); + } + else if (type == "Cavy") + { + return new Cavy(); + } + + } + + // public Pet NewPet() // пока это не потребуется - и логика в buy Pet будет существовать + // { + + // } + } +} \ No newline at end of file From 90f087e023f28a41e22f698de4acf99bfc09c40c Mon Sep 17 00:00:00 2001 From: User Date: Wed, 6 Mar 2019 14:23:28 +0300 Subject: [PATCH 24/24] lab_6_No_work --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/DateTest.cs | 33 ++++++++++++++++++++++++++ CourseApp/Date.cs | 12 ++++++++++ CourseApp/Pet.cs | 12 +++++----- CourseApp/Program.cs | 4 ++++ 5 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 CourseApp.Tests/DateTest.cs create mode 100644 CourseApp/Date.cs diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 11ab415..a6e2699 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.2 + netcoreapp2.1 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp.Tests/DateTest.cs b/CourseApp.Tests/DateTest.cs new file mode 100644 index 0000000..90eb749 --- /dev/null +++ b/CourseApp.Tests/DateTest.cs @@ -0,0 +1,33 @@ +using System; +using Xunit; +using CourseApp; + +namespace CourseApp.Tests +{ + public class DateTest + { + [Fact] + public void Test1() + { + DateTime dr = new DateTime(1990, 9, 17); + var time = Date.DateB(dr); + Assert.Equal("Год: 28 Месяц: 05 День: 20", Date.DateB(dr)); + } + + [Fact] + public void Test2() + { + DateTime dr = new DateTime(2010, 2, 2); + var time = Date.DateB(dr); + Assert.Equal("Год: 09 Месяц: 01 День: 04", Date.DateB(dr)); + } + + [Fact] + public void Test3() + { + DateTime dr = new DateTime(11, 11, 11); + var time = Date.DateB(dr); + Assert.Equal("Год: 07 Месяц: 03 День: 26", Date.DateB(dr)); + } + } + } \ No newline at end of file diff --git a/CourseApp/Date.cs b/CourseApp/Date.cs new file mode 100644 index 0000000..c21aa68 --- /dev/null +++ b/CourseApp/Date.cs @@ -0,0 +1,12 @@ +using System; + +namespace CourseApp +{ + public class Date + { + public static string DateB(DateTime dr) + { + return DateTime.Today.AddYears(-dr.Year).AddMonths(-dr.Month).AddDays(-dr.Day).ToString("Год: yy Месяц: MM День: dd"); + } + } +} \ No newline at end of file diff --git a/CourseApp/Pet.cs b/CourseApp/Pet.cs index 27fc287..022f897 100644 --- a/CourseApp/Pet.cs +++ b/CourseApp/Pet.cs @@ -19,16 +19,16 @@ public Pet(string name) // Default constructor public Pet(string name, Pet parent1, Pet parent2) // Default constructor { this.Name = name; - this.Parent1 = parent1; - this.Parent2 = parent2; + this.Pearent1 = parent1; + this.Pearent2 = parent2; } public List Childs { get; set; } public string Name {get; set; } - public Pet Parent1 {get; set; } + public Pet Pearent1 {get; set; } - public Pet Parent2 {get; set; } + public Pet Pearent2 {get; set; } public override string ToString() { @@ -38,10 +38,10 @@ public override string ToString() tostr += $", Родители: {Pearent1} и {Pearent2}"; } - if (Child != null) + if (Childs != null) { tostr += $", Дети: "; - foreach (var j in Child) + foreach (var j in Childs) { tostr += $"{j} "; } diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 792502b..1274aea 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -26,6 +26,10 @@ public static void Main() Console.WriteLine(Fan(x, a, b)); } + Console.WriteLine("Задание на даты:"); + DateTime dr = new DateTime(1999, 9, 17); + Console.WriteLine(Date.DateB(dr)); + Console.WriteLine("Кроличья ферма!"); string go;