# session six - repetição FOR **Henrique Dias Costa** #### TreinoFocadoA ```csharp= using System; using System.Collections.Generic; public class Notas { public double Nota1 { get; set; } public double Nota2 { get; set; } public double Nota3 { get; set; } } public class Retangulo { public double Base { get; set; } public double Altura { get; set; } } public class TreinoFocadoA { public List<int> GerarSequencia(int fim) { List<int> l = new List<int>(); for (int i = 0; i <= fim; i++) { l.Add(i); } return l; } public List<int> GerarSequencia(int inicio, int fim) { List<int> l = new List<int>(); for (int i = inicio; i <= fim; i++) { l.Add(i); } return l; } public List<int> GerarSequenciaPares(int inicio, int fim) { List<int> l = new List<int>(); for (int i = inicio; i <= fim; i++) { if (i % 2 == 0) l.Add(i); } return l; } public int SomarAte(int fim) { int soma = 0; for (int i = 1; i <= fim; i++) { soma += i; } return soma; } public double CalcularMedias(List<double> notas) { double soma = 0; for (int i = 0; i < notas.Count; i++) { double n = notas[i]; soma = soma + n; } double media = soma / notas.Count; return media; } public List<double> CalcularMedias(List<Notas> notas) { List<double> mediasAlunos = new List<double>(); for (int i = 0; i < notas.Count; i++) { Notas notasAluno = notas[i]; double media = (notasAluno.Nota1 + notasAluno.Nota2 + notasAluno.Nota3) / 3; mediasAlunos.Add(media); } return mediasAlunos; } public List<double> Quadrados (List<double> numeros) { List<double> quads = new List<double>(); for (int i = 0; i < numeros.Count; i++) { double n = numeros[i]; double q = Math.Pow(n, 2); quads.Add(q); } return quads; } private double AreaRetangulo(Retangulo r) { return r.Base * r.Altura; } public List<double> AreaRetangulos(List<Retangulo> retangulos) { List<double> areas = new List<double>(); for (int i = 0; i < retangulos.Count; i++) { Retangulo r = retangulos[i]; double area = AreaRetangulo(r); areas.Add(area); } return areas; } } TreinoFocadoA A = new TreinoFocadoA(); List<int> x1 = A.GerarSequencia(0); Console.WriteLine(string.Join("-", x1)); List<int> x2 = A.GerarSequencia(2, 4); Console.WriteLine(string.Join("-", x2)); List<int> x3 = A.GerarSequenciaPares(2, 4); Console.WriteLine(string.Join("-", x3)); int x4 = A.SomarAte(3); Console.WriteLine(x4); List<double> lx5 = new List<double>() { 4, 6, 8, 10 }; double x5 = A.CalcularMedias(lx5); Console.WriteLine(x5); Notas n1 = new Notas(); n1.Nota1 = 5; n1.Nota2 = 5; n1.Nota3 = 5; Notas n2 = new Notas(); n2.Nota1 = 10; n2.Nota2 = 8; n2.Nota3 = 6; Notas n3 = new Notas(); n3.Nota1 = 2; n3.Nota2 = 4; n3.Nota3 = 0; List<Notas> notas = new List<Notas>() { n1, n2, n3 }; List<double> x6 = A.CalcularMedias(notas); Console.WriteLine(string.Join("-", x6)); List<double> n7 = new List<double>() { 2,3,4,5 }; List<double> x7 = A.Quadrados(n7); Console.WriteLine(string.Join("-", x7)); List<Retangulo> retangs = new List<Retangulo>() { new Retangulo() { Base = 1, Altura = 3 }, new Retangulo() { Base = 5, Altura = 1 }, new Retangulo() { Base = 8, Altura = 2 } }; List<double> areas = treinoA.AreaRetangulos(retangs); Console.WriteLine(string.Join("-", areas)); ``` #### TreinoFocadoB ```csharp= using System; using System.Collections.Generic; public class Pessoa { public string Nome { get; set; } public DateTime Nascimento { get; set; } public override string ToString() { return "(" + Nome + "," + Nascimento.ToShortDateString() + ")"; } } public class TreinoFocadoB { public List<DateTime> GerarSequencia(int qtd) { List<DateTime> l = new List<DateTime>(); DateTime inicio = DateTime.Now.Date; for (int i = 1; i <= qtd; i++) { l.Add(inicio); inicio = inicio.AddDays(1); } return l; } public List<DateTime> GerarSequencia(int qtd, DateTime data) { List<DateTime> l = new List<DateTime>(); DateTime inicio = data; for (int i = 1; i <= qtd; i++) { l.Add(inicio); inicio = inicio.AddDays(1); } return l; } public List<Pessoa> FiltrarMaiores18(List<Pessoa> pessoas) { List<Pessoa> filtrados = new List<Pessoa>(); for (int i = 0; i < pessoas.Count; i++) { Pessoa p = pessoas[i]; if (p.Nascimento <= DateTime.Now.AddYears(-18)) { filtrados.Add(p); } } return filtrados; } public bool TodosMaiores18(List<Pessoa> pessoas) { List<Pessoa> filtrados = new List<Pessoa>(); bool todosMaiores = true; for (int i = 0; i < pessoas.Count; i++) { Pessoa p = pessoas[i]; if (p.Nascimento > DateTime.Now.AddYears(-18)) { todosMaiores = false; } } return todosMaiores; } } TreinoFocadoB treinoB = new TreinoFocadoB(); List<DateTime> x1 = treinoB.GerarSequencia(3); Console.WriteLine(string.Join(" - ", x1)); List<DateTime> x2 = treinoB.GerarSequencia(5, new DateTime(2021, 6, 10)); Console.WriteLine(string.Join(" - ", x2)); List<Pessoa> pessoas = new List<Pessoa>() { new Pessoa() { Nome = "Pessoa A", Nascimento = new DateTime(1005, 1, 1) }, new Pessoa() { Nome = "Pessoa B", Nascimento = new DateTime(1994, 1, 1) }, new Pessoa() { Nome = "Pessoa C", Nascimento = new DateTime(1000, 1, 1) }, new Pessoa() { Nome = "Pessoa D", Nascimento = new DateTime(1001, 1, 1) }, new Pessoa() { Nome = "Pessoa E", Nascimento = new DateTime(1010, 1, 1) } }; List<Pessoa> x3 = treinoB.FiltrarMaiores18(pessoas); Console.WriteLine(string.Join(" - ", x3)); bool x4 = treinoB.TodosMaiores18(pessoas); Console.WriteLine(string.Join(" - ", x4)); ``` #### TreinoFocadoC ```csharp= using System; using System.Collections.Generic; public class TreinoFocadoC { public string SepararLetras(string frase) { string nova = string.Empty; for (int i = 0; i < frase.Length; i++) { char letra = frase[i]; nova = nova + letra + "-"; } return nova; } public string Inverter(string frase) { string nova = string.Empty; for (int i = 0; i < frase.Length; i++) { char letra = frase[i]; nova = letra + nova; } return nova; } public bool ApenasCoresPrimarias(List<string> cores) { bool todasPrimarias = true; for (int i = 0; i < cores.Count; i++) { string cor = cores[i]; if (cor != "azul" && cor != "vermelho" && cor != "amarelo") { todasPrimarias = false; break; } } return todasPrimarias; } } TreinoFocadoC treinoC = new TreinoFocadoC(); string x1 = treinoC.SepararLetras("Henrique"); Console.WriteLine(x1); string x2 = treinoC.Inverter("Henrique"); Console.WriteLine(x2); bool x3 = treinoC.ApenasCoresPrimarias(new List<string>() { "amarelo", "azul" }); Console.WriteLine(x3); ``` eu acompanhei junto com a correção