# Session Six | Fundamentos Da Lógica [toc] ## Treino Focado A ```csharp= using System; using System.Collections.Generic; public class Notas{ public double N1 {get; set;} public double N2 {get; set;} public double N3 {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> L1 = new List<int>(); for (int inicio = 0; inicio <= fim; inicio++) { L1.Add(inicio); } return L1; } public List<int> GerarSequencia2 (int inicio, int fim) { List<int> L2 = new List<int> (); for(int I = inicio; I <= fim; I++) { L2.Add(I); } return L2; } public List<int> GerarSequenciaPares (int inicio, int fim) { List<int> LP = new List<int>(); for(int I = inicio; I <= fim; I++) { if( I % 2 == 0 ) { LP.Add(I); } } return LP; } public int SomaAte (int fim) { int Soma = 0; for( int I = 0; I <= fim; I++) { Soma += I; } return Soma; } public double CalcularMedias ( List<double> notas) { double media = 0; for(int I = 0 ; I < notas.Count ; I++ ) { media += notas[I]; } media /= notas.Count; return media; } public List<double> CalcularMedias2 ( List<Notas> Ln) { List<double> Medias = new List<double>(); for (int I = 0; I < Ln.Count; I++) { Notas c = Ln[I]; double M = (c.N1 + c.N2 + c.N3) / 3; Medias.Add(M); } return Medias; } public List<double> CalcularQuadrados (List<double> N) { List<double> Potencia = new List<double>(); for (int I = 0; I < N.Count; I++) { Potencia.Add( Math.Pow(N[I], 2) ); } return Potencia; } private double AreaRetangulo (Retangulo R) { return R.Base * R.Altura; } public List<double> AreaRetangulo2 (List<Retangulo> Rt) { List<double> Area = new List<double>(); for (int I = 0; I < Rt.Count; I++) { Retangulo R = Rt[I]; Area.Add( AreaRetangulo(R) ); } return Area; } } List<double> LN = new List<double>(){5.0,5.0,5.0}; Notas Na = new Notas(); Na.N1 = 5; Na.N2 = 5; Na.N3 = 5; Notas Nb = new Notas(); Nb.N1 = 6; Nb.N2 = 6; Nb.N3 = 6; Notas Nc = new Notas(); Nc.N1 = 7; Nc.N2 = 7; Nc.N3 = 7; List<Notas> ListaNotas = new List<Notas>(){Na, Nb, Nc}; Retangulo R1 = new Retangulo(); R1.Altura = 2; R1.Base = 5; Retangulo R2 = new Retangulo(); R2.Altura = 8; R2.Base = 12; Retangulo R3 = new Retangulo(); R3.Altura = 9; R3.Base = 18; List<Retangulo> ListRetangulo = new List<Retangulo>(){R1, R2, R3}; List<double> NumerosAoQuadrado = new List<double>(){2,3,4,5,6,7,8,9}; TreinoFocadoA T1 = new TreinoFocadoA (); List<int> a1 = T1.GerarSequencia(10); Console.WriteLine($"-GerarSequencia: {string.Join("-", a1)}"); List<int> b1 = T1.GerarSequencia2(10, 30); Console.WriteLine($"-GerarSequencia2: {string.Join("-", b1)}"); List<int> c1 = T1.GerarSequenciaPares(10, 30); Console.WriteLine($"-GerarSequenciaPares: {string.Join("-", c1)}"); int d1 = T1.SomaAte(10); Console.WriteLine($"-SomaAte: {d1}"); double e1 = T1.CalcularMedias( LN ); Console.WriteLine($"-CalcularMedias: {e1}"); List<double> f1 = T1.CalcularMedias2(ListaNotas); Console.WriteLine($"-CalcularMedias2: {string.Join("-", f1)}"); List<double> g1 = T1.CalcularQuadrados(NumerosAoQuadrado); Console.WriteLine($"-CalcularQuadrados: {string.Join("-", g1)}"); List<double> h1 = T1.AreaRetangulo2 (ListRetangulo); Console.WriteLine($"AreaRetangulo2: {string.Join("-", h1)}"); ``` ## Treino Focado B ```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} "; } } public class TreinoFocadoB{ public List<DateTime> GerarSequencia (int qtd) { DateTime DiaAtual = DateTime.Now; List<DateTime> Datas = new List<DateTime>(); for (int I = 0; I < qtd; I++ ) { DiaAtual = DiaAtual.AddDays(1); Datas.Add( DiaAtual ); } return Datas; } public List<DateTime> GerarSequencia2 ( DateTime DtInicial, int qtd) { List<DateTime> Dates = new List<DateTime>(); for ( int I = 0; I < qtd; I++) { Dates.Add( DtInicial.AddDays(1) ); } return Dates; } public List<DateTime> GerarSequenciaPares ( DateTime DtInicial, int qtd) { List<DateTime> Dates = new List<DateTime>(); for ( int I = 0; I < qtd; I++) { DtInicial = DtInicial.AddDays(1); if( DtInicial.Day % 2 == 0 ) { Dates.Add(DtInicial); } } return Dates; } private string Signo (DateTime N) { string signo = string.Empty; if( (N.Day >= 21 && N.Month == 3) || ( N.Day <= 20 && N.Month == 4 ) ) { signo = "Áries"; } else if( (N.Day >= 21 && N.Month == 4) || ( N.Day <= 20 && N.Month == 5 ) ) { signo = "Touro"; } else if( (N.Day >= 21 && N.Month == 5) || ( N.Day <= 20 && N.Month == 6 ) ) { signo = "Gêmeos"; } else if( (N.Day >= 21 && N.Month == 6) || ( N.Day <= 21 && N.Month == 7 ) ) { signo = "Câncer"; } else if( (N.Day >= 22 && N.Month == 7) || ( N.Day <= 22 && N.Month == 8 ) ) { signo = "Leão"; } else if( (N.Day >= 23 && N.Month == 8) || ( N.Day <= 22 && N.Month == 9 ) ) { signo = "Virgem"; } else if( (N.Day >= 23 && N.Month == 9) || ( N.Day <= 22 && N.Month == 10 ) ) { signo = "Libra"; } else if( (N.Day >= 23 && N.Month == 10) || ( N.Day <= 21 && N.Month == 11 ) ) { signo = "Escorpião"; } else if( (N.Day >= 22 && N.Month == 11) || ( N.Day <= 21 && N.Month == 12 ) ) { signo = "Sargitário"; } else if( (N.Day >= 22 && N.Month == 12) || ( N.Day <= 20 && N.Month == 1 ) ) { signo = "Capricórnio"; } else if( (N.Day >= 21 && N.Month == 1) || ( N.Day <= 19 && N.Month == 2 ) ) { signo = "Aquário"; } else if( (N.Day >= 20 && N.Month == 2) || ( N.Day <= 20 && N.Month == 3 ) ) { signo = "Peixes"; } return signo; } public List<string> Signos (List<DateTime> Datas) { List<string> NomeSignos = new List<string>(); for (int I = 0; I < Datas.Count; I++) { NomeSignos.Add( Signo(Datas[I]) ); } return NomeSignos; } public List<Pessoa> FiltrarMaiores18 (List<Pessoa> ListP) { List<Pessoa> NewListP = new List<Pessoa>(); for ( int I = 0; I < ListP.Count; I++ ) { Pessoa p = ListP[I]; if ( p.Nascimento <= DateTime.Now.AddYears(-18) ) { NewListP.Add( ListP[I] ); } } return NewListP; } public bool TodosMaiores18 ( List<Pessoa> ListP ) { bool TodosMaiores = true; for ( int I = 0; I < ListP.Count; I++ ) { Pessoa p = ListP[I]; if( p.Nascimento > DateTime.Now.AddYears(-18) ) { TodosMaiores = false; break; } } return TodosMaiores; } } List<DateTime> Dates = new List<DateTime>(){new DateTime(2005,05,14), new DateTime(2005,06,14)}; Pessoa p1 = new Pessoa(); p1.Nome = "Dani"; p1.Nascimento = new DateTime(2005,05,14); Pessoa p2 = new Pessoa(); p2.Nome = "Sensei Brunin"; p2.Nascimento = new DateTime(1987,07,19); Pessoa p3 = new Pessoa(); p3.Nome = "Robertão "; p3.Nascimento = new DateTime(1967,02,03); List<Pessoa> Lp = new List<Pessoa>() {p1, p2, p3} ; TreinoFocadoB T2 = new TreinoFocadoB(); List<DateTime> a2 = T2.GerarSequencia(1); Console.WriteLine($"-GerarSequencia: {string.Join("-", a2)}"); List<DateTime> b2 = T2.GerarSequencia2( new DateTime(2005,05,13), 1 ); Console.WriteLine($"-GerarSequencia2: {string.Join(" - ", b2)}"); List<DateTime> c2 = T2.GerarSequenciaPares ( new DateTime(2005,05,13), 5); Console.WriteLine($"-GerarSequenciaPares: {string.Join("-", c2)}"); List<string> d2 = T2.Signos(Dates); Console.WriteLine($"-Signos: {string.Join("-", d2)}"); List<Pessoa> e2 = T2.FiltrarMaiores18(Lp); Console.WriteLine($"-FiltrarMaiores18: {string.Join("",Lp)}"); bool f2 = T2.TodosMaiores18(Lp); Console.WriteLine($"-TodosMaiores18: {f2}"); Console.WriteLine(p1); ``` ## Treino Focado C ```csharp= using System; using System.Collections.Generic; public class TreinoFocadoC{ public string SepararLetras ( string nome) { string nomeseparado = string.Empty; for( int i = 0; i < nome.Length; i++) { nomeseparado = nomeseparado + nome[i] + "-"; } return nomeseparado; } public string Inverter ( string frase) { string esarf = string.Empty; for( int i = 0; i < frase.Length; i++ ) { esarf = frase[i] + esarf ; } return esarf; } public bool TodasVogais ( string frase) { bool vogal = true; for(int i = 0; i < frase.Length; i++) { if( frase[i] != 'a' && frase[i] != 'e' && frase[i] != 'i' && frase[i] != 'o' &&frase[i] != 'u' ) { vogal = false; } } return vogal; } private string UltimoNome (string Nome) { return Nome.Substring(Nome.LastIndexOf(" ") + 1); } public List<string> UltimosNomes ( List<string> nomescomp) { List<string> nome = new List<string>(); for(int i = 0; i < nomescomp.Count; i++) { nome.Add( UltimoNome(nomescomp[i]) ); } return nome; } public bool CoresPrimarias ( List<string> cores ) { bool primario = true; for( int i = 0; i < cores.Count; i++ ) { if( cores[i] != "Amarelo" && cores[i] != "Vermelho" && cores[i] != "Azul") { primario = false; } } return primario; } public bool SenhaForte (string senha) { bool forte = true; string numeros = string.Empty; string caractere = string.Empty; for(int i = 0; i < senha.Length; i++) { if(senha[i] == '1' || senha[i] == '2' || senha[i] == '3' || senha[i] == '4' || senha[i] == '5' || senha[i] == '6' || senha[i] == '7' || senha[i] == '8' || senha[i] == '9' || senha[i] == '0' ) { numeros = numeros + senha[i]; } } for( int i = 0; i < senha.Length; i++) { if ( senha[i] == '!' || senha[i] == '@' || senha[i] == '#' || senha[i] == '%' ||senha[i ] == '&' || senha[i] == '*' || senha[i] == '(' || senha[i] == ')' ) { caractere = caractere + senha[i]; } } if( senha.Length < 8 || numeros.Length < 2 || caractere.Length < 2 ) { forte = false; } return forte; } } List<string> NomesCompletos = new List<string>(){ "Daniel Aristotelis Assunção", "Bruno Oliveira", "William Santos", "Erik Alexandre" }; List<string> Cores = new List<string>(){ "Vermelho", "Amarelo", "Azul" }; TreinoFocadoC T3 = new TreinoFocadoC(); string a3 = T3.SepararLetras("William Lindo"); Console.WriteLine(a3); string b3 = T3.Inverter("Cd da Xuxa"); Console.WriteLine(b3); bool c3 = T3.TodasVogais("aaaafa"); Console.WriteLine(c3); List<string> d3 = T3.UltimosNomes(NomesCompletos); Console.WriteLine(string.Join(" - ", d3)); bool e3 = T3.CoresPrimarias(Cores); Console.WriteLine(e3); bool f3 = T3.SenhaForte("11llhhh!h*hhhhl"); Console.WriteLine(f3); ```