From 0ff756dc4dc39d70aad8f0f398f9fe292935adbc Mon Sep 17 00:00:00 2001 From: Guilherme Rocha Date: Tue, 25 May 2021 15:35:48 -0300 Subject: [PATCH 1/3] =?UTF-8?q?Comentando=20c=C3=B3digo=20at=C3=A9=20a=20a?= =?UTF-8?q?ula=203=20e=20migrando=20projeto=20para=20o=20.NET=205.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++ 01-EstruturaDoPrograma/.vscode/launch.json | 27 ------------ 01-EstruturaDoPrograma/.vscode/tasks.json | 42 ------------------- .../EstruturaDoPrograma1.csproj | 16 +++---- 02-Instrucoes/.vscode/launch.json | 27 ------------ 02-Instrucoes/.vscode/tasks.json | 42 ------------------- .../02-Instrucoes1.csproj | 17 ++++---- 02-Instrucoes/Program.cs | 22 ++++++++-- 03-Classes/.vscode/launch.json | 27 ------------ 03-Classes/.vscode/tasks.json | 42 ------------------- "03-Classes/01-Heran\303\247a/Ponto.cs" | 6 +++ "03-Classes/01-Heran\303\247a/Ponto3D.cs" | 12 +++++- 03-Classes/02-Metodos/01-Ref.cs | 5 +++ 03-Classes/02-Metodos/02-Out.cs | 3 ++ .../03-Classes1.csproj | 17 ++++---- 03-Classes/Program.cs | 12 +++++- Revisao/.vscode/launch.json | 27 ------------ Revisao/.vscode/tasks.json | 42 ------------------- .../Classes.csproj => Revisao/Revisao1.csproj | 16 +++---- 19 files changed, 91 insertions(+), 314 deletions(-) delete mode 100644 01-EstruturaDoPrograma/.vscode/launch.json delete mode 100644 01-EstruturaDoPrograma/.vscode/tasks.json rename 02-Instrucoes/Instrucoes.csproj => 01-EstruturaDoPrograma/EstruturaDoPrograma1.csproj (68%) delete mode 100644 02-Instrucoes/.vscode/launch.json delete mode 100644 02-Instrucoes/.vscode/tasks.json rename Revisao/Revisao.csproj => 02-Instrucoes/02-Instrucoes1.csproj (52%) delete mode 100644 03-Classes/.vscode/launch.json delete mode 100644 03-Classes/.vscode/tasks.json rename 01-EstruturaDoPrograma/EstruturaDoPrograma.csproj => 03-Classes/03-Classes1.csproj (53%) delete mode 100644 Revisao/.vscode/launch.json delete mode 100644 Revisao/.vscode/tasks.json rename 03-Classes/Classes.csproj => Revisao/Revisao1.csproj (68%) diff --git a/.gitignore b/.gitignore index 3e759b7..14eddbf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore +#Para o vscode +.vscode + # User-specific files *.suo *.user diff --git a/01-EstruturaDoPrograma/.vscode/launch.json b/01-EstruturaDoPrograma/.vscode/launch.json deleted file mode 100644 index 2626f34..0000000 --- a/01-EstruturaDoPrograma/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/EstruturaDoPrograma.dll", - "args": [], - "cwd": "${workspaceFolder}", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file diff --git a/01-EstruturaDoPrograma/.vscode/tasks.json b/01-EstruturaDoPrograma/.vscode/tasks.json deleted file mode 100644 index ede06b7..0000000 --- a/01-EstruturaDoPrograma/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/EstruturaDoPrograma.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/EstruturaDoPrograma.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/EstruturaDoPrograma.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/02-Instrucoes/Instrucoes.csproj b/01-EstruturaDoPrograma/EstruturaDoPrograma1.csproj similarity index 68% rename from 02-Instrucoes/Instrucoes.csproj rename to 01-EstruturaDoPrograma/EstruturaDoPrograma1.csproj index 958d2f1..1d2d39a 100644 --- a/02-Instrucoes/Instrucoes.csproj +++ b/01-EstruturaDoPrograma/EstruturaDoPrograma1.csproj @@ -1,8 +1,8 @@ - - - - Exe - netcoreapp3.0 - - - + + + + Exe + net5.0 + + + diff --git a/02-Instrucoes/.vscode/launch.json b/02-Instrucoes/.vscode/launch.json deleted file mode 100644 index 3b54462..0000000 --- a/02-Instrucoes/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/Instrucoes.dll", - "args": [], - "cwd": "${workspaceFolder}", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file diff --git a/02-Instrucoes/.vscode/tasks.json b/02-Instrucoes/.vscode/tasks.json deleted file mode 100644 index c8ace01..0000000 --- a/02-Instrucoes/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/Instrucoes.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/Instrucoes.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/Instrucoes.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/Revisao/Revisao.csproj b/02-Instrucoes/02-Instrucoes1.csproj similarity index 52% rename from Revisao/Revisao.csproj rename to 02-Instrucoes/02-Instrucoes1.csproj index c73e0d1..534e2b7 100644 --- a/Revisao/Revisao.csproj +++ b/02-Instrucoes/02-Instrucoes1.csproj @@ -1,8 +1,9 @@ - - - - Exe - netcoreapp3.1 - - - + + + + Exe + net5.0 + _02_Instrucoes1 + + + diff --git a/02-Instrucoes/Program.cs b/02-Instrucoes/Program.cs index 2d6a038..b678d2f 100644 --- a/02-Instrucoes/Program.cs +++ b/02-Instrucoes/Program.cs @@ -4,6 +4,19 @@ namespace Instrucoes { class Program { + + static void Main() + { + Declaracoes(); + + string[] a = new string[3]; + /* + a[0] = "1"; + a[1] = "2"; + a[2] = "3"; + */ + InstrucaoIf(a); + } static void Declaracoes() { int a; @@ -63,7 +76,7 @@ static void InstrucaoDo(string[] args) { texto = Console.ReadLine(); Console.WriteLine(texto); - } while (!string.IsNullOrEmpty(texto)); + } while (!string.IsNullOrEmpty(texto)); //Isso verifica se o texto é nulo ou vazio } static void InstrucaoFor(string[] args) @@ -76,7 +89,7 @@ static void InstrucaoFor(string[] args) static void InstrucaoForeach(string[] args) { - foreach (string s in args) + foreach (string s in args) //Percorre cada string presente no array { Console.WriteLine(s); } @@ -103,9 +116,10 @@ static void InstrucaoContinue(string[] args) { if (args[i].StartsWith("/")) { + //O continue chama o próximo laço e não deixa executar a próxima linha continue; } - + Console.WriteLine(args[i]); } } @@ -160,6 +174,8 @@ double Dividir(double x, double y) static void InstrucaoUsing(string[] args) { + //O using eliminar o objeto criado automaticamente após realizar as operações com ele + //Substitui o método Dispose, do garbage collection using (System.IO.TextWriter w = System.IO.File.CreateText("teste.txt")) { w.WriteLine("Line 1"); diff --git a/03-Classes/.vscode/launch.json b/03-Classes/.vscode/launch.json deleted file mode 100644 index b58c6e7..0000000 --- a/03-Classes/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/Classes.dll", - "args": [], - "cwd": "${workspaceFolder}", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file diff --git a/03-Classes/.vscode/tasks.json b/03-Classes/.vscode/tasks.json deleted file mode 100644 index e174864..0000000 --- a/03-Classes/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/Classes.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/Classes.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/Classes.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git "a/03-Classes/01-Heran\303\247a/Ponto.cs" "b/03-Classes/01-Heran\303\247a/Ponto.cs" index 4cfe248..08713d3 100644 --- "a/03-Classes/01-Heran\303\247a/Ponto.cs" +++ "b/03-Classes/01-Heran\303\247a/Ponto.cs" @@ -2,6 +2,11 @@ namespace Classes.Herança { public class Ponto { + /*public: membro acessível a qualquer classe do projeto + private: membro acessível somente dentro da classe + protected: somente classes que herdam têm acesso + internal: + */ public int x, y; private int distancia; @@ -22,6 +27,7 @@ private void CalcularDistancia2() //Faz alguma coisa... } + //virtual permite sobrescrever o método public virtual void CalcularDistancia3() { //Faz alguma coisa... diff --git "a/03-Classes/01-Heran\303\247a/Ponto3D.cs" "b/03-Classes/01-Heran\303\247a/Ponto3D.cs" index 82c805e..476fb94 100644 --- "a/03-Classes/01-Heran\303\247a/Ponto3D.cs" +++ "b/03-Classes/01-Heran\303\247a/Ponto3D.cs" @@ -1,9 +1,11 @@ namespace Classes.Herança { - public class Ponto3D : Ponto + public class Ponto3D : Ponto //Está herdando de ponto, NÃO EXISTE HERANÇA MÚLTIPLA { public int z; - public Ponto3D(int x, int y, int z) : base(x, y) + + //:base serve para passar os parâmetros recebidos para a classe pai + public Ponto3D(int x, int y, int z) : base(x, y) { this.z = z; CalcularDistancia(); @@ -13,10 +15,16 @@ public static void Calcular() { //Faz alguma coisa... } + + //override sobrescreve o método da classe base public override void CalcularDistancia3() { //Faz outra coisa ... base.CalcularDistancia3(); } + + internal void MetodoInternal(){ + + } } } \ No newline at end of file diff --git a/03-Classes/02-Metodos/01-Ref.cs b/03-Classes/02-Metodos/01-Ref.cs index 557348a..a4c3c66 100644 --- a/03-Classes/02-Metodos/01-Ref.cs +++ b/03-Classes/02-Metodos/01-Ref.cs @@ -12,7 +12,12 @@ static void Inverter(ref int x, ref int y) public static void Inverter() { int i = 1, j = 2; + + //Ao passar via ref, o método Inverter irá alterar os valores declarados nesse método; + //Com o ref as funções apotam para o mesmo local da memória Inverter(ref i, ref j); + + //$"{var}": concatena string com variável System.Console.WriteLine($"{i} {j}"); // Escreve "2 1" } } diff --git a/03-Classes/02-Metodos/02-Out.cs b/03-Classes/02-Metodos/02-Out.cs index 758e501..ab07a8e 100644 --- a/03-Classes/02-Metodos/02-Out.cs +++ b/03-Classes/02-Metodos/02-Out.cs @@ -2,6 +2,9 @@ namespace Classes.Metodos { public class Out { + + //O out define variáveis que serão preenchidas no método a ser chamado + //Assim, o método que está requisitando conseguirá obter o valor das variáveis static void Dividir(int x, int y, out int resultado, out int resto) { resultado = x / y; diff --git a/01-EstruturaDoPrograma/EstruturaDoPrograma.csproj b/03-Classes/03-Classes1.csproj similarity index 53% rename from 01-EstruturaDoPrograma/EstruturaDoPrograma.csproj rename to 03-Classes/03-Classes1.csproj index 958d2f1..7f3f638 100644 --- a/01-EstruturaDoPrograma/EstruturaDoPrograma.csproj +++ b/03-Classes/03-Classes1.csproj @@ -1,8 +1,9 @@ - - - - Exe - netcoreapp3.0 - - - + + + + Exe + net5.0 + _03_Classes1 + + + diff --git a/03-Classes/Program.cs b/03-Classes/Program.cs index 9d4a2db..7c069ff 100644 --- a/03-Classes/Program.cs +++ b/03-Classes/Program.cs @@ -1,4 +1,5 @@ using System; +using Classes.Herança; namespace Classes { @@ -6,7 +7,16 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + //instanciando objetos + Ponto p1 = new Ponto(10, 20); + + Ponto3D p2 = new Ponto3D(10, 20, 30); + + p2.MetodoInternal(); + int x = p1.x; + + Ponto3D.Calcular();//Método estático + } } } diff --git a/Revisao/.vscode/launch.json b/Revisao/.vscode/launch.json deleted file mode 100644 index 3631390..0000000 --- a/Revisao/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/Revisao.dll", - "args": [], - "cwd": "${workspaceFolder}", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "integratedTerminal", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file diff --git a/Revisao/.vscode/tasks.json b/Revisao/.vscode/tasks.json deleted file mode 100644 index 687eef2..0000000 --- a/Revisao/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/Revisao.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/Revisao.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/Revisao.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/03-Classes/Classes.csproj b/Revisao/Revisao1.csproj similarity index 68% rename from 03-Classes/Classes.csproj rename to Revisao/Revisao1.csproj index 958d2f1..1d2d39a 100644 --- a/03-Classes/Classes.csproj +++ b/Revisao/Revisao1.csproj @@ -1,8 +1,8 @@ - - - - Exe - netcoreapp3.0 - - - + + + + Exe + net5.0 + + + From 4195134ddff747e18d22d291f4f13be6088d3394 Mon Sep 17 00:00:00 2001 From: Guilherme Rocha Date: Tue, 25 May 2021 19:21:25 -0300 Subject: [PATCH 2/3] =?UTF-8?q?Refatorando=20o=20c=C3=B3digo=20e=20impedin?= =?UTF-8?q?do=20usu=C3=A1rio=20de=20disparar=20excess=C3=A3o=20ao=20cadast?= =?UTF-8?q?rar=20aluno?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "03-Classes/01-Heran\303\247a/Ponto.cs" | 2 +- Revisao/Aluno.cs | 2 + Revisao/Program.cs | 189 +++++++++++++++--------- 3 files changed, 122 insertions(+), 71 deletions(-) diff --git "a/03-Classes/01-Heran\303\247a/Ponto.cs" "b/03-Classes/01-Heran\303\247a/Ponto.cs" index 08713d3..1435bf7 100644 --- "a/03-Classes/01-Heran\303\247a/Ponto.cs" +++ "b/03-Classes/01-Heran\303\247a/Ponto.cs" @@ -5,7 +5,7 @@ public class Ponto /*public: membro acessível a qualquer classe do projeto private: membro acessível somente dentro da classe protected: somente classes que herdam têm acesso - internal: + internal: o acesso é limitado ao assembly atual */ public int x, y; private int distancia; diff --git a/Revisao/Aluno.cs b/Revisao/Aluno.cs index bda652a..0fdedb3 100644 --- a/Revisao/Aluno.cs +++ b/Revisao/Aluno.cs @@ -1,5 +1,7 @@ namespace Revisao { + + //Structs utilizam a memória Stack, que está em maior quantidade public struct Aluno { public string Nome { get; set; } diff --git a/Revisao/Program.cs b/Revisao/Program.cs index 8af6843..dbe5907 100644 --- a/Revisao/Program.cs +++ b/Revisao/Program.cs @@ -4,102 +4,151 @@ namespace Revisao { class Program { + protected static Aluno[] alunos = new Aluno[5]; //Instanciando 5 alunos + protected static int indiceAluno = 0; + + public static Boolean cadastraAluno() + { + if (indiceAluno == 5) + { + Console.WriteLine("Impossível adicionar mais alunos"); + return false; + } + Console.WriteLine("Informe o nome do aluno:"); + + var nome = Console.ReadLine(); + + //Verifica se realmente foi digitado um nome + if (string.IsNullOrEmpty(nome)) + { + Console.WriteLine("O nome do aluno não pode ser vazio! - Tente novamente"); + return false; + } + + var aluno = new Aluno(); + aluno.Nome = nome; + + Console.WriteLine("Informe a nota do aluno:"); + + //Já preenche a nota com o console.ReadLine + if (decimal.TryParse(Console.ReadLine(), out decimal nota)) + { + aluno.Nota = nota; + } + else + { + //throw new ArgumentException("Valor da nota deve ser decimal"); + Console.WriteLine("Valor da nota deve ser decimal - Tente novamente"); + return false; + } + + alunos[indiceAluno] = aluno; + indiceAluno++; + + return true; + } + + static void listaAlunos() + { + + if(string.IsNullOrEmpty(alunos[0].Nome)){ + Console.WriteLine("Nenhum aluno encontrado!"); + return; + } + + foreach (var aluno in alunos) + { + if (!string.IsNullOrEmpty(aluno.Nome)) + { + Console.WriteLine($"ALUNO: {aluno.Nome} - NOTA: {aluno.Nota}"); + } + } + } + + static void calculaMedia() + { + decimal notaTotal = 0; + var nrAlunos = 0; //Vai precisar dessa var porque o número de alunos é 5, mas pode ter menos de 5 alunos cadastrados + + //Verifica se a primeira posição está preenchida + if(string.IsNullOrEmpty(alunos[0].Nome)){ + Console.WriteLine("Nenhum aluno encontrado!"); + return; + } + + for (int i = 0; i < alunos.Length; i++) + { + if (!string.IsNullOrEmpty(alunos[i].Nome)) + { + notaTotal += alunos[i].Nota; + nrAlunos++; + } + } + + var mediaGeral = notaTotal / nrAlunos; + Conceito conceitoGeral; + + if (mediaGeral < 2) + { + conceitoGeral = Conceito.E; + } + else if (mediaGeral < 4) + { + conceitoGeral = Conceito.D; + } + else if (mediaGeral < 6) + { + conceitoGeral = Conceito.C; + } + else if (mediaGeral < 8) + { + conceitoGeral = Conceito.B; + } + else + { + conceitoGeral = Conceito.A; + } + + Console.WriteLine($"MÉDIA GERAL: {mediaGeral} - CONCEITO: {conceitoGeral}"); + } static void Main(string[] args) { - Aluno[] alunos = new Aluno[5]; - var indiceAluno = 0; + //O var permite tipagem dinâmica + string opcaoUsuario = ObterOpcaoUsuario(); + //ToUpper conver para uppercase while (opcaoUsuario.ToUpper() != "X") { switch (opcaoUsuario) { case "1": - Console.WriteLine("Informe o nome do aluno:"); - var aluno = new Aluno(); - aluno.Nome = Console.ReadLine(); - - Console.WriteLine("Informe a nota do aluno:"); - - if (decimal.TryParse(Console.ReadLine(), out decimal nota)) - { - aluno.Nota = nota; - } - else + if (cadastraAluno()) { - throw new ArgumentException("Valor da nota deve ser decimal"); + Console.WriteLine("Aluno cadastrado com sucesso!"); } - - alunos[indiceAluno] = aluno; - indiceAluno++; - break; case "2": - foreach (var a in alunos) - { - if (!string.IsNullOrEmpty(a.Nome)) - { - Console.WriteLine($"ALUNO: {a.Nome} - NOTA: {a.Nota}"); - } - } + listaAlunos(); break; case "3": - decimal notaTotal = 0; - var nrAlunos = 0; - - for (int i=0; i < alunos.Length; i++) - { - if (!string.IsNullOrEmpty(alunos[i].Nome)) - { - notaTotal = notaTotal + alunos[i].Nota; - nrAlunos++; - } - } - - var mediaGeral = notaTotal / nrAlunos; - Conceito conceitoGeral; - - if (mediaGeral < 2) - { - conceitoGeral = Conceito.E; - } - else if (mediaGeral < 4) - { - conceitoGeral = Conceito.D; - } - else if (mediaGeral < 6) - { - conceitoGeral = Conceito.C; - } - else if (mediaGeral < 8) - { - conceitoGeral = Conceito.B; - } - else - { - conceitoGeral = Conceito.A; - } - - Console.WriteLine($"MÉDIA GERAL: {mediaGeral} - CONCEITO: {conceitoGeral}"); - + calculaMedia(); break; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentException("Opção Inválida!"); } - opcaoUsuario = ObterOpcaoUsuario(); - } + } + Console.Write("Até mais!\n\n"); } private static string ObterOpcaoUsuario() { - Console.WriteLine(); - Console.WriteLine("Informe a opção desejada:"); + Console.WriteLine("\nInforme a opção desejada:"); Console.WriteLine("1- Inserir novo aluno"); Console.WriteLine("2- Listar alunos"); Console.WriteLine("3- Calcular média geral"); - Console.WriteLine("X- Sair"); - Console.WriteLine(); + Console.WriteLine("X- Sair \n"); string opcaoUsuario = Console.ReadLine(); Console.WriteLine(); From 5a141899e9c902c513aa6284440c1d46321cdb3f Mon Sep 17 00:00:00 2001 From: Guilherme Rocha Date: Thu, 27 May 2021 09:28:31 -0300 Subject: [PATCH 3/3] =?UTF-8?q?Adicionando=20c=C3=B3digo=20dos=20desafios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- projetos/desafios/Program.cs | 117 ++++++++++++++++++++++++++++++ projetos/desafios/desafios.csproj | 8 ++ 2 files changed, 125 insertions(+) create mode 100644 projetos/desafios/Program.cs create mode 100644 projetos/desafios/desafios.csproj diff --git a/projetos/desafios/Program.cs b/projetos/desafios/Program.cs new file mode 100644 index 0000000..4ccb21c --- /dev/null +++ b/projetos/desafios/Program.cs @@ -0,0 +1,117 @@ +using System; + +namespace desafios +{ + class Program + { + static void Main(string[] args) + { + + calculaNotasMoedas(); + + } + + static void calculaNotasMoedas() + { + decimal valor; + int inteiro, auxNotas, auxMoedas; + + var entrada = Console.ReadLine(); + valor = decimal.Parse(entrada); + + inteiro = (int)valor; + + + auxMoedas = (int)((valor - inteiro) * 100); + + + Console.WriteLine("NOTAS:"); + Console.WriteLine("{0} nota(s) de R$ 100.00", inteiro / 100); + auxNotas = (inteiro % 100); + + Console.WriteLine("{0} nota(s) de R$ 50.00", auxNotas / 50); + auxNotas = (auxNotas % 50); + + Console.WriteLine("{0} nota(s) de R$ 20.00", auxNotas / 20); + auxNotas = (auxNotas % 20); + + Console.WriteLine("{0} nota(s) de R$ 10.00", auxNotas / 10); + auxNotas = (auxNotas % 10); + + Console.WriteLine("{0} nota(s) de R$ 5.00", auxNotas / 5); + auxNotas = (auxNotas % 5); + + Console.WriteLine("{0} nota(s) de R$ 2.00", auxNotas / 2); + auxNotas = (auxNotas % 2); + + + Console.WriteLine("MOEDAS:"); + Console.WriteLine("{0} moeda(s) de R$ 1.00", auxNotas / 1); + + + Console.WriteLine("{0} moeda(s) de R$ 0.50", auxMoedas / 50); + auxMoedas %= 50; + + Console.WriteLine("{0} moeda(s) de R$ 0.25", auxMoedas / 25); + auxMoedas %= 25; + + Console.WriteLine("{0} moeda(s) de R$ 0.10", auxMoedas / 10); + auxMoedas %= 10; + + Console.WriteLine("{0} moeda(s) de R$ 0.05", auxMoedas / 5); + auxMoedas %= 5; + + Console.WriteLine("{0} moeda(s) de R$ 0.01", auxMoedas / 1); + } + + static void calculaCombustivelMedio() + { + int distancia; + + double combustivelGasto, consumoMedio; + + distancia = Convert.ToInt32(Console.ReadLine()); + + combustivelGasto = Convert.ToDouble(Console.ReadLine()); + + consumoMedio = distancia / combustivelGasto; + Console.WriteLine("{0:0.000} km/l", consumoMedio); + } + + public static void verificaDDD() + { + int ddd = Convert.ToInt32(Console.ReadLine()); + + switch (ddd) + { + case 61: + Console.WriteLine("Brasilia"); + break; + case 71: //complete os DDD's corretamente + Console.WriteLine("Salvador"); + break; + case 11: + Console.WriteLine("Sao Paulo"); + break; + case 21: + Console.WriteLine("Rio de Janeiro"); + break; + case 32: + Console.WriteLine("Juiz de Fora"); + break; + case 19: + Console.WriteLine("Campinas"); + break; + case 27: + Console.WriteLine("Vitoria"); + break; + case 31: + Console.WriteLine("Belo Horizonte"); + break; + default: + Console.WriteLine("DDD nao cadastrado"); + break; + } + } + } +} diff --git a/projetos/desafios/desafios.csproj b/projetos/desafios/desafios.csproj new file mode 100644 index 0000000..1d2d39a --- /dev/null +++ b/projetos/desafios/desafios.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + +