Advertisement
adrianodassis

At 29/09 sem verificação

Sep 28th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.35 KB | None | 0 0
  1. //main
  2. package appnotas1;
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class AppNotas1 {
  7.      
  8.     public static void main(String[] args){
  9.         Scanner entrada = new Scanner(System.in);
  10.         Notas1 obj = new Notas1();
  11.        
  12.         System.out.print("Digite o número de provas: ");
  13.         int provas = entrada.nextInt();
  14.        
  15.         System.out.print("Digite o número de alunos: ");
  16.         int alunos = entrada.nextInt();  
  17.         System.out.println("");
  18.        
  19.         double n1[] = new double[alunos];
  20.        
  21.         obj.setQuantidade(alunos,provas);
  22.         obj.insereNotasAluno(n1);
  23.         obj.imprimir();
  24.        
  25.         System.out.println("Média Total da sala é: " + obj.media());
  26.     }
  27.    
  28. }
  29.  
  30. //class
  31.  
  32. package appnotas1;
  33.  
  34. import java.util.Scanner;
  35.  
  36. public class Notas1 {
  37.  
  38.     double notas[][];
  39.     int qntProvas;
  40.     int qntAlunos;
  41.  
  42.     public void setQuantidade(int qntAlunos, int qntProvas) {
  43.         this.qntAlunos = qntAlunos;
  44.         this.qntProvas = qntProvas;
  45.         this.notas = new double[qntAlunos][qntProvas];
  46.     }
  47.  
  48.     public void insereNotasAluno(double v[]) {
  49.         Scanner entrada = new Scanner(System.in);
  50.        
  51.         for (int j = 0; j < notas.length; j++) {
  52.             System.out.println("Aluno " + (j + 1) + ": ");
  53.             for (int k = 0; k < notas[j].length; k++) {
  54.                 System.out.print("Nota da " + (k + 1) + "ª prova: ");
  55.                 v[j] = entrada.nextDouble();
  56.                
  57.                 notas[j][k] = v[j];
  58.             }
  59.             System.out.println("");
  60.         }
  61.  
  62.     }
  63.  
  64.     public void imprimir() {
  65.         System.out.println("");
  66.         System.out.println("            Notas");
  67.  
  68.         for (int linha = 0; linha < notas.length; linha++) {
  69.             System.out.print("Aluno " + (linha + 1) + ":");
  70.             for (int coluna = 0; coluna < notas[linha].length; coluna++) {
  71.                 System.out.print(" " + notas[linha][coluna] + " ");
  72.             }
  73.             System.out.println("");
  74.         }
  75.     }
  76.  
  77.     public double media() {
  78.         double media, mediaS = 0;
  79.  
  80.         for (int l = 0; l < notas.length; l++) {
  81.             for (int c = 0; c < notas[l].length; c++) {
  82.                 mediaS += notas[l][c];
  83.             }
  84.         }
  85.         media = mediaS / (qntAlunos * qntProvas);
  86.  
  87.         return media;
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement