diff --git a/TestDotNetVrSystem/Task1.cs b/TestDotNetVrSystem/Task1.cs index 29e6e56..b4747f7 100644 --- a/TestDotNetVrSystem/Task1.cs +++ b/TestDotNetVrSystem/Task1.cs @@ -8,7 +8,14 @@ public class Task1 * Dada a lista de inteiros, retorne o maior número da lista */ public static int? GetMax(List list) - { + { int max = 0; + int i; + + for (i = 0; i < list.Count; i++) { + if(max < list[i]) max = list[i]; + } + + return max; } } } diff --git a/TestDotNetVrSystem/Task2.cs b/TestDotNetVrSystem/Task2.cs index 9c4fd22..157f59b 100644 --- a/TestDotNetVrSystem/Task2.cs +++ b/TestDotNetVrSystem/Task2.cs @@ -1,4 +1,6 @@ -namespace TestDotNetVrSystem + +using System; +namespace TestDotNetVrSystem { public class Task2 { @@ -21,6 +23,23 @@ public class Task2 */ public static bool CheckInput(string input) { + int i; + + if(input.Length != 7) return false; + + for( i =0; i< input.Length; i++ ) { + + if (i <= 2 && (Char.IsDigit(input[i]) || (Char.IsLower(input[i])))) { + return false; + } + + if (i > 2 && Char.IsLetter(input[i])) { + return false; + } + } + + return true; + } } } diff --git a/TestDotNetVrSystem/Task3.cs b/TestDotNetVrSystem/Task3.cs index d49024f..9ddea6c 100644 --- a/TestDotNetVrSystem/Task3.cs +++ b/TestDotNetVrSystem/Task3.cs @@ -10,6 +10,14 @@ public class Task3 */ public static int GetSum(List list) { + int sum = 0; + int i; + + for (i=0; i< list.Count; i++) { + if (list[i] > 0) sum+= list[i]; + } + + return sum; } } } diff --git a/TestDotNetVrSystem/Task4.cs b/TestDotNetVrSystem/Task4.cs index 826350e..b4171c6 100644 --- a/TestDotNetVrSystem/Task4.cs +++ b/TestDotNetVrSystem/Task4.cs @@ -10,6 +10,20 @@ public class Task4 */ public static List GetStudentsByBirth() { + Repository Repo = new Repository(); + List studentsThisYear = new List(); + int i; + int year = 2020; + + + for (i=0; i< Repo.Students.Count; i++) + if(Repo.Students[i].Birth.Year == year) + studentsThisYear.Add(Repo.Students[i]); + + + return studentsThisYear; + + } } } diff --git a/TestDotNetVrSystem/Task5.cs b/TestDotNetVrSystem/Task5.cs index 8f08577..75f3c25 100644 --- a/TestDotNetVrSystem/Task5.cs +++ b/TestDotNetVrSystem/Task5.cs @@ -8,6 +8,15 @@ public class Task5 */ public static string GetEvenOrOdd(int number) { + if (number == 0) { + return "zero"; + } + else if (number % 2 == 0) { + return "par"; + } + else { + return "impar"; + } } } } diff --git a/TestDotNetVrSystem/Task6.cs b/TestDotNetVrSystem/Task6.cs index 7fc72b1..8dcb869 100644 --- a/TestDotNetVrSystem/Task6.cs +++ b/TestDotNetVrSystem/Task6.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; - +using System; namespace TestDotNetVrSystem { public class Task6 @@ -17,6 +17,47 @@ public class Task6 */ public static List GetRatios(List numbers) { + int positiveCount = 0; + int negativeCount = 0; + int zeroCount = 0; + + double positiveRatio; + double negativeRatio; + double zeroRatio; + + + List listRatios = new List(); + int i; + + int listLength = numbers.Count; + + for (i = 0; i < listLength; i++) + { + if (numbers[i] == 0) + { + zeroCount += 1; + + } + else if (numbers[i] > 0) + { + positiveCount += 1; + } + else + { + negativeCount += 1; + } + } + + positiveRatio = (double) positiveCount / listLength; + negativeRatio = (double) negativeCount / listLength; + zeroRatio = (double) zeroCount / listLength; + + listRatios.Add((decimal) Math.Round(positiveRatio, 6)); + listRatios.Add((decimal) Math.Round(negativeRatio, 6)); + listRatios.Add((decimal) Math.Round(zeroRatio, 6)); + + return listRatios; + } } } diff --git a/TestDotNetVrSystem/Task7.cs b/TestDotNetVrSystem/Task7.cs index 601eb24..a73d099 100644 --- a/TestDotNetVrSystem/Task7.cs +++ b/TestDotNetVrSystem/Task7.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; - +using TestDotNetVrSystem.HelpClasses; namespace TestDotNetVrSystem { public class Task7 @@ -10,14 +10,42 @@ public class Task7 */ public static List GetProductsOutOfStock() { + int i; + Repository Repo = new Repository(); + List productsOutofStock = new List(); + + + for (i = 0; i < Repo.Products.Count; i++) + { + if (Repo.Products[i].Stock.Quantity == 0) + { + productsOutofStock.Add(Repo.Products[i].Name); + } + } + + return productsOutofStock; } + + /* * 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() { + int i; + int sumQuantity = 0; + Repository Repo = new Repository(); + + + for (i = 0; i < Repo.Products.Count; i++) + { + sumQuantity += Repo.Products[i].Stock.Quantity; + } + + + return sumQuantity; } /* @@ -28,6 +56,24 @@ public static int GetSumStock() */ public static bool IsSalePossible(int productId, int orderQuantity) { + int i; + Repository Repo = new Repository(); + + + for (i = 0; i < Repo.Products.Count; i++) + { + if (productId == Repo.Products[i].Id) + if (Repo.Products[i].Stock.Quantity >= orderQuantity) + { + return true; + } else + { + return false; + } + } + + + return false; } } }