Atividade 1
Dictionary<string, List<double>> alunos = new Dictionary<string, List<double>>()
{
{ "Sunny", new List<double>() {10, 7.7} },
{ "Mordret", new List<double>() { 7.7 } }
};
alunos["Nephis"] = new List<double>() { 7.2, 8.3 };
alunos.Add("Cassia", new List<double>() { 10, 9.8 });
alunos["Mordret"].Add(10);
Media();
void Media()
{
foreach (var aluno in alunos)
{
string nome = aluno.Key;
List<double> notasAluno = aluno.Value;
double total = 0;
foreach (var nota in notasAluno)
{
total += nota;
}
double media = total / notasAluno.Count;
Console.WriteLine($"\nMédia de {nome}: {media.ToString("F2")}");
}
}
Atividade 2
void ExibirTitulo(string titulo)
{
int quantidadeLetras = titulo.Length;
string asteriscos = string.Empty.PadLeft(quantidadeLetras, '*');
Console.WriteLine(asteriscos);
Console.WriteLine(titulo);
Console.WriteLine(asteriscos);
}
var estoque = new Dictionary<string, int>()
{
{"Laranja", 7 },
{"Abacaxi", 10 },
{"Maçã", 4 },
{"Banana", 2 }
};
void pedirEBuscarPedido()
{
ExibirTitulo("Bem vindos a Loja!!!");
Console.WriteLine("Produtos que servimos:");
foreach (string produto in estoque.Keys)
{
Console.WriteLine($"->{produto}");
}
Console.Write($"\nPor favor digite o nome do produto que oferecemos abaixo \npara saber" +
$" sua quantidade: ");
string resposta = Console.ReadLine()!;
if (estoque.ContainsKey(resposta))
{
Console.WriteLine($"\nExistem {estoque[resposta]} {resposta}s no estoque");
}
else
{
Console.WriteLine("\nNão foi encontrado o item pedido");
}
}
pedirEBuscarPedido();