¡GoConqr estrena diseño! Cuéntanos qué te parece.

Apuntes

Exercicio C#

Luiz Cardamone Portugués 1 página

Contenido del apunte (1)

Página 1

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Exercicos

{

class Program

{

static void Main(string[] args)

{

while (true)

{

int Decisao;

Console.Clear();

Console.Write(Painel.PainelPrincila());

bool BolDecisao = int.TryParse(Console.ReadLine(), out Decisao);

if (BolDecisao)

{

if (Decisao == 1)

{

if (Repositorio.Pessoas.Count == 0)

{

Mensage_De_Erro.SemIncluses();

}

else

{

Console.Write("\n Pessoas inclusas:");

Repositorio.Listar();

}

Console.ReadLine();

}

else if (Decisao == 2)

{

Console.Write($"\n Informe o Nome: ");

string NomeEntrada = Console.ReadLine();

if (NomeEntrada == "")

{

Mensage_De_Erro.EntradaDedaDoInvalida();

}

else

{

int EntradaIdade;

Console.Write($" Informe a Idade: ");

bool boolEntradaIdade = int.TryParse(Console.ReadLine(), out EntradaIdade);

if (boolEntradaIdade && EntradaIdade != 0)

{

Repositorio.Add(NomeEntrada, EntradaIdade);

Console.Write("\n Inclusão realizada com sucesso\n Aperte qualquer tecla para voltar.");

}

else

{

Mensage_De_Erro.EntradaDedaDoInvalida();

}

}

Console.ReadLine();

}

else if (Decisao == 3)

{

if (Repositorio.Pessoas.Count == 0)

{

Console.Write("\n Não ha Registros no Sistema\n Aperte qualquer tecla para voltar.");

}

else

{

int IntEntradaExclusao;

Console.Write("\n Informe o Id da pessoa que deseja Excluir.");

bool BoolEntradaExclusao = int.TryParse(Console.ReadLine(), out IntEntradaExclusao);

if (BoolEntradaExclusao)

{

Repositorio.Excluir(IntEntradaExclusao);

}

else

{

Mensage_De_Erro.EntradaDedaDoInvalida();

}

Console.ReadLine();

}

Console.ReadLine();

}

else if (Decisao == 0)

{

break;

}

else

{

Mensage_De_Erro.OpcaoErrada(Decisao);

Console.ReadLine();

}

}

else

{

Console.Write($"\n Opção escolhida invalida.\n Reinicie o processo.");

Console.ReadLine();

}

}

}

}

public class Pessoa

{

public int Id { get; private set; }

public string Nome { get; }

public int Idade { get; }

public Pessoa(int id, string nome, int idade)

{

this.Id = id;

this.Nome = nome;

this.Idade = idade;

}

}

public static class Repositorio

{

private static int _id = 0;

public static List<Pessoa> Pessoas = new List<Pessoa>();

public static void Add(string nome, int idade)

{

_id++;

var add = new Pessoa(_id, nome, idade);

Pessoas.Add(add);

}

public static void Listar()

{

for (int i = 0; i < Pessoas.Count; i++)

{

Console.Write($"\n ID: {Pessoas[i].Id}\n Nome: {Pessoas[i].Nome}\n Idade: {Pessoas[i].Idade} \n");

}

}

public static void Excluir(int id)

{

for (int i = 0; i < Pessoas.Count; i++)

{

if (Pessoas[i].Id == id)

{

Pessoas.RemoveAt(i);

Console.Write($"\n A Exclusão do codigo {id} foi realizada com sucesso !");

break;

}

else if ((i + 1) == Pessoas.Count)

{

Mensage_De_Erro.Exclusao_sem_correspondecia(id);

}

}

}

}

public static class Painel

{

public static string PainelPrincila()

{

string _strPainel = "";

int _intLarguraPainel = 40;

string _strLinha = "";

string _strDadoPainel = "";

string _strEspaco = "";

for (int i = 0; i < _intLarguraPainel; i++)

{

if (i < 3)

{

_strLinha += " ";

}

else

{

_strLinha += "*";

}

}

for (int i = 0; i < _intLarguraPainel - 2; i++)

{

_strEspaco += " ";

}

_strDadoPainel += " *" + _strEspaco + "*\n";

_strDadoPainel += " * Desenvolvido por Luiz Cardamone *\n";

_strDadoPainel += " *" + _strEspaco + "*\n";

_strDadoPainel += " *" + _strEspaco + "*\n";

_strDadoPainel += " * Cadastro de Pessoas. *\n";

_strDadoPainel += " *" + _strEspaco + "*\n";

_strDadoPainel += " * Selecione uma das opções abaixo: *\n";

_strDadoPainel += " *" + _strEspaco + "*\n";

_strDadoPainel += " * 1 - Listar Pessoas *\n";

_strDadoPainel += " * 2 - Incluir nova pessoa *\n";

_strDadoPainel += " * 3 - Exluir Pessoa *\n";

_strDadoPainel += " *" + _strEspaco + "*\n";

_strDadoPainel += " * ou tecle '0' para SAIR *\n";

_strDadoPainel += " *" + _strEspaco + "*\n";

_strPainel = "\n" + _strLinha + "\n" + _strDadoPainel + _strLinha;

_strPainel += "\n Digite a pção: ";

return _strPainel;

}

}

public static class Mensage_De_Erro

{

private static string _aPT = "\n Aperte qualquer tecla para reinicar.";

public static void Exclusao_sem_correspondecia(int id)

{

Console.Write($"\n Id {id} sem correspondencia. {_aPT}");

}

public static void OpcaoErrada(int opcao)

{

Console.Write($"\n Opção escolhida {opcao} invalida. {_aPT}");

}

public static void SemIncluses()

{

Console.Write($"\n Não há Pessoas inclusas . {_aPT}");

}

public static void EntradaDedaDoInvalida()

{

Console.Write($"\n Entrada de Dado Invalida, Reinicie o processo.");

}

}

}

Información

Descripción
Apunte sobre Exercicio C#, creado por Luiz Cardamone el 23/08/2019.
Creado por
Luiz Cardamone
Visitas
1
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?