diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 95b27949..eda431a2 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet: [ '2.1', '3.1.x', '5.0.x' ] + dotnet: [ '6.0.x' ] steps: - uses: actions/checkout@v1 diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 158d6300..cff59f20 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp5 + netcoreapp6.0 True false diff --git a/CourseApp.Tests/UnitTestsClass.cs b/CourseApp.Tests/UnitTestsClass.cs new file mode 100644 index 00000000..0a66f735 --- /dev/null +++ b/CourseApp.Tests/UnitTestsClass.cs @@ -0,0 +1,22 @@ +namespace CourseApp.Tests +{ + using Xunit; + + public class UnitTestsClass + { + [Theory] + [InlineData("VSCode", "Exe", "1.56", "GB")] + [InlineData("ISUCT", "HTML", "0.79", "KB")] + [InlineData("Program", "Cs", "0.47", "B")] + [InlineData("Music", "Mp3", "1.56", "KB")] + [InlineData("Cat", "Exe", "1.56", "MB")] + [InlineData("Video", "Mov", "0.63", "TB")] + public void TestClass(string name, string extension, string weight, string weightModificator) + { + var expected = $"{name}.{extension} {weight}{weightModificator}"; + var file = new FileCreator(name, extension, weight, weightModificator); + var actual = file.Display(); + Assert.Equal(expected, actual); + } + } +} diff --git a/CourseApp.Tests/UnitTestsData.cs b/CourseApp.Tests/UnitTestsData.cs new file mode 100644 index 00000000..3e84a5ac --- /dev/null +++ b/CourseApp.Tests/UnitTestsData.cs @@ -0,0 +1,64 @@ +namespace CourseApp.Tests +{ + using System; + using Xunit; + + public class UnitTestsData + { + [Theory] + [InlineData(2021, 10, 15, 2002, 4, 24, "19 5 21")] + [InlineData(2021, 10, 15, 2006, 4, 21, "15 5 24")] + [InlineData(2021, 10, 15, 2012, 5, 24, "9 4 21")] + public void TestAge(int todayYear, int todayMonth, int todayDay, int birthYear, int birthMonth, int birthDay, string expected) + { + DateTime birth = new DateTime(birthYear, birthMonth, birthDay); + DateTime today = new DateTime(todayYear, todayMonth, todayDay); + var dateClass = new DateClass(); + var date = dateClass.CalculateAge(birth, today); + var actual = $"{date.Item1} {date.Item2} {date.Item3}"; + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2021, 10, 15, 2002, 4, 24, "19 year`s 5 month`s 21 day ")] + [InlineData(2021, 10, 15, 2006, 4, 21, "15 year`s 5 month`s 24 day`s")] + [InlineData(2021, 10, 15, 2012, 5, 24, "9 year`s 4 month`s 21 day ")] + public void TestCreateOutputAge(int todayYear, int todayMonth, int todayDay, int birthYear, int birthMonth, int birthDay, string expected) + { + DateTime birth = new DateTime(birthYear, birthMonth, birthDay); + DateTime today = new DateTime(todayYear, todayMonth, todayDay); + var dateClass = new DateClass(); + var date = dateClass.CreateOutput(dateClass.CalculateAge(birth, today)); + var actual = $"{date.Item1} {date.Item2} {date.Item3}"; + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2021, 10, 15, 2002, 4, 24, "6 9")] + [InlineData(2021, 10, 15, 2006, 4, 21, "6 6")] + [InlineData(2021, 10, 15, 2012, 5, 24, "7 9")] + public void TestDaysToBirthDay(int todayYear, int todayMonth, int todayDay, int birthYear, int birthMonth, int birthDay, string expected) + { + DateTime birth = new DateTime(birthYear, birthMonth, birthDay); + DateTime today = new DateTime(todayYear, todayMonth, todayDay); + var dateClass = new DateClass(); + var date = dateClass.CalculateDaysToBirthDay(birth, today); + var actual = $"{date.Item1} {date.Item2}"; + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2021, 10, 15, 2002, 4, 24, "6 month`s 9 day`s to your birthDay")] + [InlineData(2021, 10, 15, 2006, 10, 15, " Happy birthDay!")] + [InlineData(2021, 10, 15, 2012, 10, 14, " 1 day from your birthDay")] + public void TestCreateOutputDaysToBirthDay(int todayYear, int todayMonth, int todayDay, int birthYear, int birthMonth, int birthDay, string expected) + { + DateTime birth = new DateTime(birthYear, birthMonth, birthDay); + DateTime today = new DateTime(todayYear, todayMonth, todayDay); + var dateClass = new DateClass(); + var date = dateClass.CreateOutput(dateClass.CalculateDaysToBirthDay(birth, today)); + var actual = $"{date.Item1} {date.Item2} {date.Item3}"; + Assert.Equal(expected, actual); + } + } +} diff --git a/CourseApp.Tests/InputValueUnitTests.cs b/CourseApp.Tests/UnitTestsInputValue.cs similarity index 92% rename from CourseApp.Tests/InputValueUnitTests.cs rename to CourseApp.Tests/UnitTestsInputValue.cs index 4b055458..58bd4680 100644 --- a/CourseApp.Tests/InputValueUnitTests.cs +++ b/CourseApp.Tests/UnitTestsInputValue.cs @@ -1,9 +1,8 @@ namespace CourseApp.Tests { - using CourseApp.Program.Input; using Xunit; - public class InputValueUnitTests + public class UnitTestsInputValue { [Theory] [InlineData(0, -1, 2, true)] @@ -44,11 +43,11 @@ public void TestInputInt(string item, int minValue, int maxValue, bool expected) } [Theory] - [InlineData("2.2", 0, 3, true)] + [InlineData("0", 0, 3, true)] [InlineData("-1.5", 0, 3, false)] [InlineData("r", 0, 3, false)] [InlineData("-1", -2, -1, true)] - [InlineData("4.1", 4, 5, true)] + [InlineData("4", 4, 5, true)] [InlineData(" ", 4, 4, false)] public void TestInputDouble(string item, int minValue, int maxValue, bool expected) { diff --git a/CourseApp.Tests/UnitTests.cs b/CourseApp.Tests/UnitTestsTask.cs similarity index 97% rename from CourseApp.Tests/UnitTests.cs rename to CourseApp.Tests/UnitTestsTask.cs index e6a403a8..a7e8a6c1 100644 --- a/CourseApp.Tests/UnitTests.cs +++ b/CourseApp.Tests/UnitTestsTask.cs @@ -1,11 +1,10 @@ namespace CourseApp.Tests { using System.Collections.Generic; - using CourseApp.Program; using Xunit; using static System.Math; - public class UnitTests + public class UnitTestsTask { [Theory] [InlineData(3, 2, 0.11, 1.56)] diff --git a/CourseApp/.vscode/launch.json b/CourseApp/.vscode/launch.json index 5e1043fc..03bbd5f9 100644 --- a/CourseApp/.vscode/launch.json +++ b/CourseApp/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/bin/Debug/netcoreapp5/CourseApp.dll", + "program": "${workspaceFolder}/bin/Debug/netcoreapp6.0/CourseApp.dll", "args": [], "cwd": "${workspaceFolder}", "console": "externalTerminal", diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 20032b88..d5480420 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp5 + netcoreapp6.0 True diff --git a/CourseApp/MainFile.cs b/CourseApp/MainFile.cs index 00111e58..60ec8f91 100644 --- a/CourseApp/MainFile.cs +++ b/CourseApp/MainFile.cs @@ -1,14 +1,20 @@ namespace CourseApp { using System; - using CourseApp.Program; public class MainFile { public static void Main(string[] args) { - var userInterface = new UserInterface(); - userInterface.StartPage(); + var taskUserInterface = new TaskUserInterface(); + taskUserInterface.StartPage(); + var classUserInterface = new ClassUserInterfaceClass(); + classUserInterface.StartPage(); + var dataUserInterface = new DataUserInterface(); + dataUserInterface.StartPage(); + var zooUserInterface = new ZooUserInterface(); + var zoo = new Zoo("Moscow zoo"); + zooUserInterface.Draw(zoo); Console.ReadLine(); } } diff --git a/CourseApp/Program/CalculateTasks.cs b/CourseApp/Program/1 - CalculateTask/CalculateTasks.cs similarity index 98% rename from CourseApp/Program/CalculateTasks.cs rename to CourseApp/Program/1 - CalculateTask/CalculateTasks.cs index d37568bb..4f4089a3 100644 --- a/CourseApp/Program/CalculateTasks.cs +++ b/CourseApp/Program/1 - CalculateTask/CalculateTasks.cs @@ -1,4 +1,4 @@ -namespace CourseApp.Program +namespace CourseApp { using System.Collections.Generic; using static System.Math; diff --git a/CourseApp/Program/UserInterface.cs b/CourseApp/Program/1 - CalculateTask/TaskUserInterface.cs similarity index 95% rename from CourseApp/Program/UserInterface.cs rename to CourseApp/Program/1 - CalculateTask/TaskUserInterface.cs index f19481a7..07d6914b 100644 --- a/CourseApp/Program/UserInterface.cs +++ b/CourseApp/Program/1 - CalculateTask/TaskUserInterface.cs @@ -1,12 +1,11 @@ -namespace CourseApp.Program +namespace CourseApp { using System; using System.Collections.Generic; - using CourseApp.Program.Input; - public class UserInterface + public class TaskUserInterface { - public UserInterface() + public TaskUserInterface() { Console.WriteLine("Hello!"); } @@ -39,8 +38,6 @@ public void StartPage() break; } } - - Environment.Exit(0); } private void DefaultCalculations(List listValues) diff --git a/CourseApp/Program/2 - ClassTask/ClassUserInterfaceClass.cs b/CourseApp/Program/2 - ClassTask/ClassUserInterfaceClass.cs new file mode 100644 index 00000000..3390ff08 --- /dev/null +++ b/CourseApp/Program/2 - ClassTask/ClassUserInterfaceClass.cs @@ -0,0 +1,129 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public class ClassUserInterfaceClass + { + public void StartPage() + { + var isEnabled = true; + while (isEnabled) + { + var input = new InputValues(); + Console.WriteLine(@" + In this program you can: + 1 - Get default file + 2 - Get custom file + 3 - Exit program + What you want? Enter integer values."); + switch (input.InputInt(1, 3)) + { + case 1: + DefaultFile(); + break; + + case 2: + CustomFile(); + break; + case 3: + isEnabled = false; + break; + } + } + } + + private void DefaultFile() + { + Console.Clear(); + var input = new InputValues(); + var file = new FileCreator("Program", "Cs", "0.34", "MB"); + Console.WriteLine($@"Default file: +{file.Display()}"); + } + + private void CustomFile() + { + Console.Clear(); + List customValues = InputCustomValues(); + while (customValues.Count != 4) + { + customValues = InputCustomValues(); + } + + var file = new FileCreator(customValues); + Console.WriteLine($"Custom file{file.Display()}"); + } + + private List InputCustomValues() + { + Console.Clear(); + var customValues = new List(); + customValues.Add(EnumValueName()); + customValues.Add(EnumValueExtension()); + customValues.Add(EnterValue()); + customValues.Add(EnumValueWeightModificator()); + Console.Clear(); + return customValues; + } + + private string EnumValueName() + { + Console.Clear(); + var name = string.Empty; + var input = new InputValues(); + var enumLength = Enum.GetNames(typeof(EnumName)).Length; + Console.WriteLine($"Choose avaible name. Enter integer values."); + for (int i = 0; i < enumLength; i++) + { + Console.WriteLine($"{i + 1} - {Enum.GetName(typeof(EnumName), i)}"); + } + + Console.WriteLine("Your variant:"); + var id = input.InputInt(1, enumLength) - 1; + name = Enum.GetName(typeof(EnumName), id); + return name; + } + + private string EnumValueExtension() + { + Console.Clear(); + var input = new InputValues(); + var enumLength = Enum.GetNames(typeof(EnumExtension)).Length; + Console.WriteLine($"Choose avaible extension. Enter integer values."); + for (var i = 0; i < enumLength; i++) + { + Console.WriteLine($"{i + 1} - {Enum.GetName(typeof(EnumExtension), i)}"); + } + + Console.WriteLine("Your variant:"); + var id = input.InputInt(1, enumLength) - 1; + return Enum.GetName(typeof(EnumExtension), id); + } + + private string EnumValueWeightModificator() + { + Console.Clear(); + var input = new InputValues(); + var enumLength = Enum.GetNames(typeof(EnumWeightModificator)).Length; + Console.WriteLine($"Choose avaible weightModificator. Enter integer values."); + for (var i = 0; i < enumLength; i++) + { + Console.WriteLine($"{i + 1} - {Enum.GetName(typeof(EnumWeightModificator), i)}"); + } + + Console.WriteLine("Your variant:"); + var id = input.InputInt(1, Enum.GetNames(typeof(EnumWeightModificator)).Length) - 1; + return Enum.GetName(typeof(EnumWeightModificator), id); + } + + private string EnterValue() + { + var input = new InputValues(); + Console.Clear(); + Console.WriteLine(@"Enter weight. Weight must be positive. Value range is (0.001 to 1023). +Your value:"); + return input.InputDouble(0.001, 1023).ToString(); + } + } +} diff --git a/CourseApp/Program/2 - ClassTask/Enums/EnumExtension.cs b/CourseApp/Program/2 - ClassTask/Enums/EnumExtension.cs new file mode 100644 index 00000000..8e2855ae --- /dev/null +++ b/CourseApp/Program/2 - ClassTask/Enums/EnumExtension.cs @@ -0,0 +1,21 @@ +namespace CourseApp +{ + public enum EnumExtension + { + Txt, + Pdf, + Jpeg, + Cs, + Html, + Png, + Abb, + Mp3, + Mp4, + Apk, + Exe, + Tif, + Gif, + Jpg, + Bak, + } +} diff --git a/CourseApp/Program/2 - ClassTask/Enums/EnumName.cs b/CourseApp/Program/2 - ClassTask/Enums/EnumName.cs new file mode 100644 index 00000000..a120a421 --- /dev/null +++ b/CourseApp/Program/2 - ClassTask/Enums/EnumName.cs @@ -0,0 +1,23 @@ +namespace CourseApp +{ + public enum EnumName + { + ISUCT, + Funny, + Test, + Car, + Page, + IDE, + Game, + Video, + Music, + Work, + Phone, + Note, + File, + Diploma, + Peoples, + IT, + CsharpCourse, + } +} \ No newline at end of file diff --git a/CourseApp/Program/2 - ClassTask/Enums/EnumWeightModificator.cs b/CourseApp/Program/2 - ClassTask/Enums/EnumWeightModificator.cs new file mode 100644 index 00000000..978cf337 --- /dev/null +++ b/CourseApp/Program/2 - ClassTask/Enums/EnumWeightModificator.cs @@ -0,0 +1,12 @@ +namespace CourseApp +{ + public enum EnumWeightModificator + { + B, + KB, + MB, + GB, + TB, + PB, + } +} \ No newline at end of file diff --git a/CourseApp/Program/2 - ClassTask/FileCreator.cs b/CourseApp/Program/2 - ClassTask/FileCreator.cs new file mode 100644 index 00000000..80b0b97b --- /dev/null +++ b/CourseApp/Program/2 - ClassTask/FileCreator.cs @@ -0,0 +1,42 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public class FileCreator + { + public FileCreator(string filename, string extension, string weight, string weightModificator) + { + FileName = filename; + Extension = extension; + Weight = weight; + WeightModificator = weightModificator; + } + + public FileCreator(List customValues) + { + if (customValues.Count != 4) + { + throw new NullReferenceException(); + } + + FileName = customValues[0]; + Extension = customValues[1]; + Weight = customValues[2]; + WeightModificator = customValues[3]; + } + + public string FileName { get; set; } + + public string Extension { get; set; } + + public string Weight { get; set; } + + public string WeightModificator { get; set; } + + public string Display() + { + return $"{FileName}.{Extension} {Weight}{WeightModificator}"; + } + } +} diff --git a/CourseApp/Program/3 - DateTask/DataUserInterface.cs b/CourseApp/Program/3 - DateTask/DataUserInterface.cs new file mode 100644 index 00000000..5b1ef4fe --- /dev/null +++ b/CourseApp/Program/3 - DateTask/DataUserInterface.cs @@ -0,0 +1,173 @@ +namespace CourseApp +{ + using System; + + public class DataUserInterface + { + public DataUserInterface() + { + Console.WriteLine("Hello!"); + IsValuesEnter = false; + } + + public bool IsValuesEnter { get; set; } + + public int Year { get; set; } + + public int Month { get; set; } + + public int Day { get; set; } + + public void StartPage() + { + var isEnabled = true; + while (isEnabled) + { + var input = new InputValues(); + Console.WriteLine(@" +Avaible actions: +1 - Set your birthDay +2 - Get your age +3 - Get date to your birthDay +4 - Exit program +What you want? Enter integer values."); + switch (input.InputInt(1, 4)) + { + case 1: + SetYourBirthDate(); + break; + + case 2: + GetAge(); + break; + + case 3: + GetDateToYourBirth(); + break; + + case 4: + isEnabled = false; + break; + } + } + } + + public void Output(string message) + { + switch (message) + { + case "days": + var days = Date(); + var line = string.Empty; + if (string.IsNullOrEmpty(days.Item1) && string.IsNullOrEmpty(days.Item2)) + { + line = $"{days.Item3}"; + } + + if (!string.IsNullOrEmpty(days.Item1) && !string.IsNullOrEmpty(days.Item2)) + { + line = $"{days.Item1}, {days.Item2} {days.Item3}"; + } + + if (string.IsNullOrEmpty(days.Item1) || string.IsNullOrEmpty(days.Item2)) + { + if (string.IsNullOrEmpty(days.Item1)) + { + line = $"{days.Item2} {days.Item3}"; + } + + if (string.IsNullOrEmpty(days.Item2)) + { + line = $"{days.Item1} {days.Item3}"; + } + } + + Console.WriteLine(line); + break; + + case "age": + var age = Age(); + Console.WriteLine($"Your age: {age.Item1}, {age.Item2} and {age.Item3}"); + break; + } + } + + private void SetYourBirthDate() + { + Console.Clear(); + var input = new InputValues(); + var today = DateTime.Now; + Console.WriteLine("Enter your birthday"); + Console.WriteLine("Year:"); + Year = input.InputInt(0001, today.Year); + Console.WriteLine("Month:"); + if (Year == today.Year) + { + Month = input.InputInt(1, today.Month); + } + else + { + Month = input.InputInt(1, 12); + } + + Console.WriteLine("Day:"); + if (Month == today.Month) + { + Day = input.InputInt(1, today.Day); + } + else + { + Day = input.InputInt(1, 31); + } + + IsValuesEnter = true; + Console.Clear(); + } + + private void GetAge() + { + Console.Clear(); + var input = new InputValues(); + if (IsValuesEnter) + { + Output("age"); + } + else + { + Console.WriteLine("You dont enter your birthDay!"); + } + } + + private void GetDateToYourBirth() + { + Console.Clear(); + var input = new InputValues(); + if (IsValuesEnter) + { + Output("days"); + } + else + { + Console.WriteLine("You dont enter your birthDay!"); + } + } + + private (string, string, string) Age() + { + var dateClass = new DateClass(); + var birthDay = new DateTime(Year, Month, Day); + var dateToday = DateTime.Today; + var date = dateClass.CreateOutput(dateClass.CalculateAge(birthDay, dateToday)); + return (date.Item1, date.Item2, date.Item3); + } + + private (string, string, string) Date() + { + var dateClass = new DateClass(); + var birthDay = new DateTime(Year, Month, Day); + var dateToday = DateTime.Today; + var date = dateClass.CreateOutput(dateClass.CalculateDaysToBirthDay(birthDay, dateToday)); + return (date.Item1, date.Item2, date.Item3); + } + } +} diff --git a/CourseApp/Program/3 - DateTask/DateClass.cs b/CourseApp/Program/3 - DateTask/DateClass.cs new file mode 100644 index 00000000..02499e9c --- /dev/null +++ b/CourseApp/Program/3 - DateTask/DateClass.cs @@ -0,0 +1,89 @@ +namespace CourseApp +{ + using System; + using static System.Math; + + public class DateClass + { + public (int, int, int) CalculateAge(DateTime birthDay, DateTime dateToday) + { + var months = dateToday.Month - birthDay.Month; + var years = dateToday.Year - birthDay.Year; + if (dateToday.Day < birthDay.Day) + { + months--; + } + + if (months < 0) + { + years--; + months += 12; + } + + var days = (dateToday - birthDay.AddMonths((years * 12) + months)).Days; + return (years, months, days); + } + + public (string, string, string) CreateOutput((int, int, int) age) + { + var years = $"{age.Item1} year{(age.Item1 % 10 == 1 ? " " : "`s")}"; + var months = $"{age.Item2} month{(age.Item2 % 10 == 1 ? " " : "`s")}"; + var days = $"{age.Item3} day{(age.Item3 % 10 == 1 ? " " : "`s")}"; + return (years, months, days); + } + + public (string, string, string) CreateOutput((int, int) age) + { + var months = string.Empty; + var days = string.Empty; + var mod = "Happy birthDay!"; + if (age.Item1 + age.Item2 != 0) + { + months = string.Empty; + days = string.Empty; + if (age.Item1 != 0) + { + months = $"{age.Item1} {(age.Item1 % 10 == 1 ? "month" : "month`s")}"; + mod = "to your birthDay"; + if (age.Item1 < 0) + { + months = $"{Abs(age.Item1)} {(Abs(age.Item1) % 10 == 1 ? "month" : "month`s")}"; + mod = "from your birthDay"; + } + } + + if (age.Item2 != 0) + { + days = $"{age.Item2} {(age.Item2 % 10 == 1 ? "day" : "day`s")}"; + mod = "to your birthDay"; + if (age.Item2 < 0) + { + days = $"{Abs(age.Item2)} {(Abs(age.Item2) % 10 == 1 ? "day" : "day`s")}"; + mod = "from your birthDay"; + } + } + } + + return (months, days, mod); + } + + public (int, int) CalculateDaysToBirthDay(DateTime birthDay, DateTime dateToday) + { + var months = birthDay.Month - dateToday.Month; + var years = birthDay.Year - dateToday.Year; + if (birthDay.Year < dateToday.Day) + { + months--; + } + + if (months < 0) + { + years--; + months += 12; + } + + var days = (birthDay - dateToday.AddMonths((years * 12) + months)).Days; + return (months, days); + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Abstract/Animal.cs b/CourseApp/Program/4 - ZooTask/Abstract/Animal.cs new file mode 100644 index 00000000..a89b62b2 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Abstract/Animal.cs @@ -0,0 +1,21 @@ +namespace CourseApp +{ + public abstract class Animal + { + public Animal(string type, string size, int age, string ability) + { + Type = type; + Size = size; + Age = age; + Ability = ability; + } + + public string Type { get; set; } + + public string Size { get; set; } + + public int Age { get; set; } + + public string Ability { get; set; } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Abstract/People.cs b/CourseApp/Program/4 - ZooTask/Abstract/People.cs new file mode 100644 index 00000000..1ec8f57a --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Abstract/People.cs @@ -0,0 +1,15 @@ +namespace CourseApp +{ + public abstract class People + { + public People(string name, int age) + { + Name = name; + Age = age; + } + + public string Name { get; set; } + + public int Age { get; set; } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Abstract/Staff.cs b/CourseApp/Program/4 - ZooTask/Abstract/Staff.cs new file mode 100644 index 00000000..eb4691ad --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Abstract/Staff.cs @@ -0,0 +1,18 @@ +namespace CourseApp +{ + public abstract class Staff + { + public Staff(string type, string size, string material) + { + Type = type; + Size = size; + Material = material; + } + + public string Type { get; set; } + + public string Size { get; set; } + + public string Material { get; set; } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Animals/Bird.cs b/CourseApp/Program/4 - ZooTask/Animals/Bird.cs new file mode 100644 index 00000000..25489f50 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Animals/Bird.cs @@ -0,0 +1,27 @@ +namespace CourseApp +{ + using System; + + public class Bird : Animal, IDrawable + { + public Bird(string type, string size, int age, string ability) + : base(type, size, age, ability) + { + Type = type; + Size = size; + Age = age; + Ability = ability; + } + + public void Draw() + { + var information = @$" Class: Bird + Type: {(string.IsNullOrEmpty(Type) ? "none" : Type)} + Size: {(string.IsNullOrEmpty(Size) ? "none" : Size)} + Age: {(Age <= 0 ? "none" : Age)}y + Ability: {(string.IsNullOrEmpty(Ability) ? "none" : Ability)} + "; + Console.WriteLine(information); + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Animals/Fish.cs b/CourseApp/Program/4 - ZooTask/Animals/Fish.cs new file mode 100644 index 00000000..0a73384c --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Animals/Fish.cs @@ -0,0 +1,27 @@ +namespace CourseApp +{ + using System; + + public class Fish : Animal, IDrawable + { + public Fish(string type, string size, int age, string ability) + : base(type, size, age, ability) + { + Type = type; + Size = size; + Age = age; + Ability = ability; + } + + public void Draw() + { + var information = @$" Class: Fish + Type: {(string.IsNullOrEmpty(Type) ? "none" : Type)} + Size: {(string.IsNullOrEmpty(Size) ? "none" : Size)} + Age: {(Age <= 0 ? "none" : Age)}y + Ability: {(string.IsNullOrEmpty(Ability) ? "none" : Ability)} + "; + Console.WriteLine(information); + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Animals/FourLegged.cs b/CourseApp/Program/4 - ZooTask/Animals/FourLegged.cs new file mode 100644 index 00000000..b277064b --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Animals/FourLegged.cs @@ -0,0 +1,27 @@ +namespace CourseApp +{ + using System; + + public class FourLegged : Animal, IDrawable + { + public FourLegged(string type, string size, int age, string ability) + : base(type, size, age, ability) + { + Type = type; + Size = size; + Age = age; + Ability = ability; + } + + public void Draw() + { + var information = @$" Class: FourLegged + Type: {(string.IsNullOrEmpty(Type) ? "none" : Type)} + Size: {(string.IsNullOrEmpty(Size) ? "none" : Size)} + Age: {(Age <= 0 ? "none" : Age)}y + Ability: {(string.IsNullOrEmpty(Ability) ? "none" : Ability)} + "; + Console.WriteLine(information); + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Interface/IDrawable.cs b/CourseApp/Program/4 - ZooTask/Interface/IDrawable.cs new file mode 100644 index 00000000..c9062f60 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Interface/IDrawable.cs @@ -0,0 +1,7 @@ +namespace CourseApp +{ + public interface IDrawable + { + public void Draw(); + } +} diff --git a/CourseApp/Program/4 - ZooTask/Interface/ZooUserInterface.cs b/CourseApp/Program/4 - ZooTask/Interface/ZooUserInterface.cs new file mode 100644 index 00000000..78ea212c --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Interface/ZooUserInterface.cs @@ -0,0 +1,20 @@ +namespace CourseApp +{ + using System.Collections.Generic; + + public class ZooUserInterface + { + public void Draw(IDrawable obj) + { + obj.Draw(); + } + + public void Draw(List objects) + { + foreach (IDrawable obj in objects) + { + this.Draw(obj); + } + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Objects/Building.cs b/CourseApp/Program/4 - ZooTask/Objects/Building.cs new file mode 100644 index 00000000..98c1bc63 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Objects/Building.cs @@ -0,0 +1,25 @@ +namespace CourseApp +{ + using System; + + public class Building : Staff, IDrawable + { + public Building(string type, string size, string material) + : base(type, size, material) + { + Type = type; + Size = size; + Material = material; + } + + public void Draw() + { + var information = @$" Class: Building + Type: {(string.IsNullOrEmpty(Type) ? "none" : Type)} + Size: {(string.IsNullOrEmpty(Size) ? "none" : Size)} + Material: {(string.IsNullOrEmpty(Material) ? "none" : Material)} + "; + Console.WriteLine(information); + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Objects/InteriorObject.cs b/CourseApp/Program/4 - ZooTask/Objects/InteriorObject.cs new file mode 100644 index 00000000..fb81340f --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Objects/InteriorObject.cs @@ -0,0 +1,25 @@ +namespace CourseApp +{ + using System; + + public class InteriorObject : Staff, IDrawable + { + public InteriorObject(string type, string size, string material) + : base(type, size, material) + { + Type = type; + Size = size; + Material = material; + } + + public void Draw() + { + var information = @$" Class: InteriorObject + Type: {(string.IsNullOrEmpty(Type) ? "none" : Type)} + Size: {(string.IsNullOrEmpty(Size) ? "none" : Size)} + Material: {(string.IsNullOrEmpty(Material) ? "none" : Material)} + "; + Console.WriteLine(information); + } + } +} \ No newline at end of file diff --git a/CourseApp/Program/4 - ZooTask/Peoples/Employee.cs b/CourseApp/Program/4 - ZooTask/Peoples/Employee.cs new file mode 100644 index 00000000..05e34495 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Peoples/Employee.cs @@ -0,0 +1,31 @@ +namespace CourseApp +{ + using System; + + public class Employee : People, IDrawable + { + public Employee(string name, string post, int age, int salary) + : base(name, age) + { + Name = name; + Post = post; + Age = age; + Salary = salary; + } + + public int Salary { get; set; } + + public string Post { get; set; } + + public void Draw() + { + var information = @$" Class: Employee + Name: {(string.IsNullOrEmpty(Name) ? "none" : Name)} + Post: {(string.IsNullOrEmpty(Post) ? "none" : Post)} + Age: {(Age <= 0 ? "none" : Age)}y + Salary: {(string.IsNullOrEmpty(Salary.ToString()) ? "none" : Salary)}$ + "; + Console.WriteLine(information); + } + } +} \ No newline at end of file diff --git a/CourseApp/Program/4 - ZooTask/Peoples/Visitor.cs b/CourseApp/Program/4 - ZooTask/Peoples/Visitor.cs new file mode 100644 index 00000000..34fc2789 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Peoples/Visitor.cs @@ -0,0 +1,23 @@ +namespace CourseApp +{ + using System; + + public class Visitor : People, IDrawable + { + public Visitor(string name, int age) + : base(name, age) + { + Name = name; + Age = age; + } + + public void Draw() + { + var information = @$" Class: Employee + Name: {(string.IsNullOrEmpty(Name) ? "none" : Name)} + Age: {(string.IsNullOrEmpty(Age.ToString()) ? "none" : Age)}y + "; + Console.WriteLine(information); + } + } +} \ No newline at end of file diff --git a/CourseApp/Program/4 - ZooTask/Zoo.cs b/CourseApp/Program/4 - ZooTask/Zoo.cs new file mode 100644 index 00000000..d51e2453 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Zoo.cs @@ -0,0 +1,63 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public class Zoo : IDrawable + { + public Zoo(string name) + { + Name = name; + } + + public string Name { get; set; } + + public void Draw() + { + var zooUserInterface = new ZooUserInterface(); + Console.WriteLine($"Zoo: {Name}"); + Console.WriteLine($"Animals:"); + zooUserInterface.Draw(Animals()); + Console.WriteLine($"Peoples:"); + zooUserInterface.Draw(Peoples()); + Console.WriteLine($"Objects:"); + zooUserInterface.Draw(Objects()); + } + + public List Animals() + { + var list = new List(); + list.Add(new Bird("Hummingbird", "Very small", 1, null)); + list.Add(new Bird("Eagle", "Small", 2, "Fly")); + list.Add(new FourLegged("Lion", "Medium", 5, null)); + list.Add(new FourLegged("Wolf", "Medium", 2, "Howl")); + list.Add(new Fish("Shark", "Big", 2, "Swim")); + list.Add(new Fish("Swordfish", "Medium", 3, "Swim")); + return list; + } + + public List Peoples() + { + var list = new List(); + list.Add(new Employee("Mike", "Director", 35, 0)); + list.Add(new Employee("Leo", "Сleaner", 56, 1300)); + list.Add(new Employee("Mark", "Worker", 0, 1300)); + list.Add(new Visitor("Stepa", 19)); + list.Add(new Visitor("Daniil", 11)); + list.Add(new Visitor("Gleb", 34)); + return list; + } + + public List Objects() + { + var list = new List(); + list.Add(new Building("Administration", "Big", null)); + list.Add(new Building("Toilet", "Small", "Wood")); + list.Add(new Building("Shop", "Medium", "Concrete")); + list.Add(new InteriorObject("Table", "Medium", "Wood")); + list.Add(new InteriorObject("Laptop", "Medium", null)); + list.Add(new InteriorObject("Char", null, null)); + return list; + } + } +} \ No newline at end of file diff --git a/CourseApp/Program/Input/CheckValues.cs b/CourseApp/Program/Input/CheckValues.cs index 96981581..7eae6ef4 100644 --- a/CourseApp/Program/Input/CheckValues.cs +++ b/CourseApp/Program/Input/CheckValues.cs @@ -1,4 +1,4 @@ -namespace CourseApp.Program.Input +namespace CourseApp { using System; diff --git a/CourseApp/Program/Input/InputValues.cs b/CourseApp/Program/Input/InputValues.cs index 83862351..f662d7db 100644 --- a/CourseApp/Program/Input/InputValues.cs +++ b/CourseApp/Program/Input/InputValues.cs @@ -1,4 +1,4 @@ -namespace CourseApp.Program.Input +namespace CourseApp { using System; @@ -72,15 +72,13 @@ public double InputDouble(double minValue, double maxValue) (number, isCorrect) = InputDouble(minValue, maxValue, item); if (isCorrect) { - break; + return number; } else { Console.WriteLine($"Please enter correct value!"); } } - - return number; } public (double, bool) InputDouble(double minValue, double maxValue, string item) diff --git a/courseworkspace.code-workspace b/courseworkspace.code-workspace index a24280d9..bdc25edf 100644 --- a/courseworkspace.code-workspace +++ b/courseworkspace.code-workspace @@ -1,15 +1,17 @@ { "folders": [ { + "name": "CourseApp", "path": "CourseApp" }, { + "name": "CourseApp.Tests", "path": "CourseApp.Tests" }, { - "name": "Configs (Root)", - "path": "." - }, + "name": "Configs (Root)", + "path": "." + } ], "settings": {} } \ No newline at end of file