From 3fbd65d1088254f2dfd9672934f54d17533c5f0c Mon Sep 17 00:00:00 2001 From: MatheusNRei Date: Mon, 23 Nov 2020 20:50:29 -0300 Subject: [PATCH 1/2] =?UTF-8?q?Resolu=C3=A7=C3=A3o=20Parcial.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tasks/HelpClasses/Repository.cs | 32 ++++++++++++------------- Tasks/HelpClasses/Student.cs | 4 ++-- Tasks/Task1.cs | 7 +++++- Tasks/Task2.cs | 42 +++++++++++++++++++++++++++++++-- Tasks/Task3.cs | 18 ++++++++++++-- Tasks/Task4.cs | 5 +++- Tasks/Task5.cs | 24 ++++++++++++++++++- Tasks/Task6.cs | 22 ++++++++++++++++- Tasks/Task7.cs | 15 ++++++++---- Tasks/Tasks.csproj | 1 + Tasks/packages.config | 4 ++++ 11 files changed, 143 insertions(+), 31 deletions(-) create mode 100644 Tasks/packages.config diff --git a/Tasks/HelpClasses/Repository.cs b/Tasks/HelpClasses/Repository.cs index 324c31c..df8f77a 100644 --- a/Tasks/HelpClasses/Repository.cs +++ b/Tasks/HelpClasses/Repository.cs @@ -5,7 +5,7 @@ namespace Tasks.HelpClasses { public class Repository { - public List Students; + public List Students; public List Products; public Repository() @@ -14,22 +14,22 @@ public Repository() Products = GetProducts(); } - private static List GetStudents() + private static List GetStudents() { - List students = new List(); - - students.Add(new Student(1, $"Student1", new DateTime(2020, 1, 1))); - students.Add(new Student(2, $"Student2", new DateTime(2010, 1, 1))); - students.Add(new Student(3, $"Student3", new DateTime(2011, 1, 1))); - students.Add(new Student(4, $"Student4", new DateTime(2012, 1, 1))); - students.Add(new Student(5, $"Student5", new DateTime(2013, 1, 1))); - students.Add(new Student(6, $"Student6", new DateTime(2014, 1, 1))); - students.Add(new Student(7, $"Student7", new DateTime(2015, 1, 1))); - students.Add(new Student(8, $"Student8", new DateTime(2016, 1, 1))); - students.Add(new Student(9, $"Student9", new DateTime(2017, 1, 1))); - students.Add(new Student(10, $"Student10", new DateTime(2018, 1, 1))); - students.Add(new Student(11, $"Student11", new DateTime(2019, 1, 1))); - students.Add(new Student(12, $"Student12", new DateTime(2020, 10, 31))); + List students = new List(); + + students.Add(new student(1, $"Student1", new DateTime(2020, 1, 1))); + students.Add(new student(2, $"Student2", new DateTime(2010, 1, 1))); + students.Add(new student(3, $"Student3", new DateTime(2011, 1, 1))); + students.Add(new student(4, $"Student4", new DateTime(2012, 1, 1))); + students.Add(new student(5, $"Student5", new DateTime(2013, 1, 1))); + students.Add(new student(6, $"Student6", new DateTime(2014, 1, 1))); + students.Add(new student(7, $"Student7", new DateTime(2015, 1, 1))); + students.Add(new student(8, $"Student8", new DateTime(2016, 1, 1))); + students.Add(new student(9, $"Student9", new DateTime(2017, 1, 1))); + students.Add(new student(10, $"Student10", new DateTime(2018, 1, 1))); + students.Add(new student(11, $"Student11", new DateTime(2019, 1, 1))); + students.Add(new student(12, $"Student12", new DateTime(2020, 10, 31))); return students; } diff --git a/Tasks/HelpClasses/Student.cs b/Tasks/HelpClasses/Student.cs index 4d807b0..9a3798c 100644 --- a/Tasks/HelpClasses/Student.cs +++ b/Tasks/HelpClasses/Student.cs @@ -2,9 +2,9 @@ namespace Tasks.HelpClasses { - public class Student + public class student { - public Student(int id, string name, DateTime birth) + public student(int id, string name, DateTime birth) { Id = id; Name = name; diff --git a/Tasks/Task1.cs b/Tasks/Task1.cs index e1e3892..f4db4e7 100644 --- a/Tasks/Task1.cs +++ b/Tasks/Task1.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace Tasks { @@ -7,6 +8,10 @@ public class Task1 /* * Dada a lista de inteiros, retorne o maior número da lista */ - public static int? GetMax(List list) { } + public static int? GetMax(List list) { + var valmax = list.Max(); + return valmax; + } } } + diff --git a/Tasks/Task2.cs b/Tasks/Task2.cs index 82b84b8..de73768 100644 --- a/Tasks/Task2.cs +++ b/Tasks/Task2.cs @@ -1,4 +1,7 @@ -namespace Tasks +using System.Linq; +using System.Text.RegularExpressions; + +namespace Tasks { public class Task2 { @@ -20,6 +23,41 @@ public class Task2 * 3 - abc1324 * 4 - az111W */ - public static bool CheckInput(string input) { } + public static bool CheckInput(string input) + { + + int upcase = 0; + int lowcase = 0; + int num = 0; + bool result = false; + + + for (int i = 0; i < input.Length; i++) + { + char ch = input[i]; + if (ch >= 'A' && ch <= 'Z') + upcase++; + else if (ch >= 'a' && ch <= 'z') + lowcase++; + else if (ch >= '0' && ch <= '9') + num++; + if (upcase >= 3) + { + if (lowcase >= 1) + { + if (num >= 4) + { + result = true; + } + } + } + else + result = false; + }return result; + } } } + + + + diff --git a/Tasks/Task3.cs b/Tasks/Task3.cs index a41fa26..c9786a6 100644 --- a/Tasks/Task3.cs +++ b/Tasks/Task3.cs @@ -8,6 +8,20 @@ public class Task3 * Dada a lista de inteiros, retorne o somatório de todos os itens com valor POSITIVO da lista * LEMBRANDO que 0 (zero) NÃO é um número positivo */ - public static int GetSum(List list) { } - } + public static int GetSum(List list) + { + + int sum = 0; + foreach (int item in list) + { + if (item > 0) { + sum = item +sum; + + + } + + } + return sum; + } } + } diff --git a/Tasks/Task4.cs b/Tasks/Task4.cs index 37ec3d4..6fb3aa9 100644 --- a/Tasks/Task4.cs +++ b/Tasks/Task4.cs @@ -9,6 +9,9 @@ public class Task4 * Desenvolva um método que retorne todos os estudantes do Repositório que nasceram em 2020 * Dica: A classe Repository possui as informções dos Students */ - public static List GetStudentsByBirth() { } + public static List GetStudentsByBirth() + { + List Students; + } } } diff --git a/Tasks/Task5.cs b/Tasks/Task5.cs index c4f93f4..8dcc23d 100644 --- a/Tasks/Task5.cs +++ b/Tasks/Task5.cs @@ -6,6 +6,28 @@ public class Task5 *Crie um método que receba um inteiro e retorne "impar" caso seja impar e "par" caso seja par *Caso o número seja 0 (zero), retorne "zero" */ - public static string GetEvenOrOdd(int number) { } + public static string GetEvenOrOdd(int number) + { + string result = ""; + + if (number % 2 == 0) + { + result = ("par"); + } + + + + if (number % 2 != 0) + { + result = ("impar"); + } + + if (number == 0) + { + result = ("zero"); + } + + return result; + } } } diff --git a/Tasks/Task6.cs b/Tasks/Task6.cs index b0f6ae7..63ab0de 100644 --- a/Tasks/Task6.cs +++ b/Tasks/Task6.cs @@ -15,6 +15,26 @@ public class Task6 * 0.333333 * 0.166667 */ - public static List GetRatios(List numbers) { } + public static List GetRatios(List numbers) { + int i = 0; + int negnum = 0; + int zeronum = 0; + int posnum = 0; + for (i = 0; i <= numbers.Count; i++) + { + if (numbers[i] > 0) + posnum = posnum / negnum / zeronum; + numbers.Add(posnum); + if (numbers[i] < 0) + negnum = negnum / posnum / zeronum; + numbers.Add(negnum); + if (numbers[i] == 0) + zeronum = zeronum / negnum / posnum; + numbers.Add(zeronum); + + } + return numbers.ConvertAll(x => (decimal)x); + + } } } diff --git a/Tasks/Task7.cs b/Tasks/Task7.cs index 6fcc824..b086584 100644 --- a/Tasks/Task7.cs +++ b/Tasks/Task7.cs @@ -8,20 +8,25 @@ public class Task7 * Desenvolma um método que retorne o nome dos produtos que estão com estoque zerado * Dica: A classe Repository possui as informções dos Products */ - public static List GetProductsOutOfStock() { } - + public static List GetProductsOutOfStock() { + return null; + } /* * Desenvolma um método que retorne a soma total das quantidades de estoque dos itens * Dica: A classe Repository possui as informções dos Products */ - public static int GetSumStock() { } - + public static int GetSumStock() + { + return 0; + } /* * Crie um método que verifique, dado Id e quantidade solicitada do produto * se o mesmo possui quantidade em estoque para venda * Dica: A classe Repository possui as informções dos Products * */ - public static bool IsSalePossible(int productId, int orderQuantity) { } + public static bool IsSalePossible(int productId, int orderQuantity) { + return false; + } } } diff --git a/Tasks/Tasks.csproj b/Tasks/Tasks.csproj index bfe9ab8..3e46589 100644 --- a/Tasks/Tasks.csproj +++ b/Tasks/Tasks.csproj @@ -59,6 +59,7 @@ + \ No newline at end of file diff --git a/Tasks/packages.config b/Tasks/packages.config new file mode 100644 index 0000000..a6f18b8 --- /dev/null +++ b/Tasks/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From d46dc00b06187dc2023694fe0aaaf41b0642a4fd Mon Sep 17 00:00:00 2001 From: MatheusNRei Date: Tue, 24 Nov 2020 04:58:25 -0300 Subject: [PATCH 2/2] Parcial --- Tasks/Task4.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Tasks/Task4.cs b/Tasks/Task4.cs index 6fb3aa9..8616d28 100644 --- a/Tasks/Task4.cs +++ b/Tasks/Task4.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using Tasks.HelpClasses; namespace Tasks @@ -11,7 +13,13 @@ public class Task4 */ public static List GetStudentsByBirth() { - List Students; + var repository = new Repository(); + List students = new List(); + var result = Enumerable.Range(0, students.Count) + .Select(id => students[id].Birth.Year == 2020) + .ToList(); + return result; + } } }