Quantcast
Channel: Tópicos
Viewing all articles
Browse latest Browse all 11336

Problema com código e criação de tabela

$
0
0
Boa tarde, using System.Collections; namespace ex1 { class Program { static void Main(string[] args) { ArrayList turma = new ArrayList(); EstudanteInf estundante = new EstudanteInf("joao Ramos", 20, 15); turma.Add(estundante); estundante = new EstudanteInf("tiago", 15, 16); turma.Add(estundante); estundante = new EstudanteInf("andre", 13, 13); turma.Add(estundante); estundante = new EstudanteInf("pedro", 13, 13); turma.Add(estundante); estundante = new EstudanteInf("diogo", 13, 15); turma.Add(estundante); estundante = new EstudanteInf("goncalo", 13, 16); turma.Add(estundante); estundante = new EstudanteInf("bruno", 13, 17); turma.Add(estundante); estundante = new EstudanteInf("francisco", 13, 18); turma.Add(estundante); estundante = new EstudanteInf("andre", 13, 19); turma.Add(estundante); estundante = new EstudanteInf("pascoal", 8, 3); turma.Add(estundante); estundante = new EstudanteInf("afonso", 9, 5); turma.Add(estundante); //imprime cabecalho Console.WriteLine("╔═════════════════════════════════╦═══════════╦══════════╦═══════════════════════════╗"); Console.WriteLine("║ Nome ║ Teste 1 ║ Teste 2 ║ Classificação Final ║"); Console.WriteLine("╠═════════════════════════════════╬═══════════╬══════════╬═══════════════════════════╣"); foreach (EstudanteInf value in turma) { string toPrint = "║" + Value.lernome() + Value.lerTeste1() + Value.lerTeste2() + Value.classFinal() + "║"; } //imprime a ultima linha Console.WriteLine("╚═════════════════════════════════╦═══════════╦══════════╦═══════════════════════════╝"); // System.Console.WriteLine(); System.Console.Read(); } } } Class using System; namespace ex1 { class EstudanteInf { string Nome; Double Teste1; Double Teste2; private string p; public EstudanteInf(string NomeDoAluno, Double NotaTeste1, Double NotaTeste2) { Nome = NomeDoAluno; Teste1 = NotaTeste1; Teste2 = NotaTeste2; } public EstudanteInf(string p) { // TODO: Complete member initialization this.p = p; } public Double classFinal() { Double media = (Teste1 + Teste2) / 2; return media; } public string lerNome() { return Nome; } public string lerTeste1() { return Teste1.toString(); } public string lerTeste2() { return Teste2.toString(); } public void escreveNome(string NomeDoAluno) { Nome = NomeDoAluno; } public void escrevenotaTeste1(Double notaTeste1) { Teste1 = notaTeste1; } public void escrevenotaTeste2(Double notaTeste2) { Teste2 = notaTeste2; } public string situacaoDoAluno() { double classificacaoFinal = classFinal(); if (classificacaoFinal >= 10) { return "Aprovado"; } else { if (classificacaoFinal >= 8) return "Admitido a oral"; else { return "reprovado"; } } } internal void imprimir() { throw new NotImplementedException(); } } } Ainda podes optimizar imenso o código e por exemplo colocar uma validação para o nome dar o numero exacto de caracteres para obteres a "grelha" toda formatada correctamente, mas isso é um bom exercício para tu fazeres! Cordiais cumprimentos, Apocsantos

Viewing all articles
Browse latest Browse all 11336

Trending Articles