fork download
  1. import java.util.Scanner;
  2. class Aluno
  3. {
  4. public int[] nota = {0,0,0,0};
  5. }
  6.  
  7. class Nota
  8. {
  9. private Aluno[] aluno;
  10. private int totalAlunos;
  11. private int NumeroNotas;
  12. public Nota(int numero_alunos, int numero_notas)
  13. {
  14. this.totalAlunos = numero_alunos;
  15. this.NumeroNotas = numero_notas;
  16. this.aluno = new Aluno[numero_alunos];
  17. for(int i = 0; i < totalAlunos; i++)
  18. {
  19. this.aluno[i] = new Aluno();
  20. }
  21. for(int numero_de_alunos = 0; numero_de_alunos < numero_alunos; numero_de_alunos++)
  22. {
  23. System.out.print("Aluno " + (numero_de_alunos+1) + ":\n");
  24. Scanner Scan = new Scanner(System.in);
  25. for(int i = 0; i < NumeroNotas; i++)
  26. {
  27. System.out.print("Digite a nota número " + (i+1) + ": ");
  28. this.aluno[numero_de_alunos].nota[i] = Scan.nextInt();
  29. System.out.print("\n");
  30. }
  31. }
  32. }
  33. public int PegarMedia(int NumeroAluno)
  34. {
  35. int stack = 0;
  36. for(int i = 0; i < NumeroNotas; i++)
  37. {
  38. stack += this.aluno[NumeroAluno].nota[i];
  39. }
  40. return stack / NumeroNotas;
  41.  
  42. }
  43. public void MostrarMedia()
  44. {
  45. for(int i = 0; i < totalAlunos; i++)
  46. {
  47. System.out.print("Media do aluno " + i + ":");
  48. System.out.print(PegarMedia(i) + "\n");
  49. }
  50. System.out.print("\n");
  51. }
  52. }
  53. //Fim das classes
  54.  
  55. class Test
  56. {
  57. public static void main(String args[])
  58. {
  59. Nota notas = new Nota(1,5);
  60. notas.MostrarMedia();
  61. }
  62. }
  63.  
  64.  
Runtime error #stdin #stdout #stderr 0.1s 380672KB
stdin
Standard input is empty
stdout
Aluno 1:
Digite a nota número 1: 
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:907)
	at java.util.Scanner.next(Scanner.java:1530)
	at java.util.Scanner.nextInt(Scanner.java:2160)
	at java.util.Scanner.nextInt(Scanner.java:2119)
	at Nota.<init>(Main.java:28)
	at Test.main(Main.java:59)