Tenho de fazer um programa que tenha 3 classes. A principal, uma de alunos e outra da turma. Na da turma devo fazer um método que calcule a média das médias dos alunos. Já consegui fazer a classe principal e a de alunos. Mas não consegui fazer a da turma, pois não consigo popular os dados com array. Alguém pode ajudar?
Envio abaixo as classes:
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package controlenotasmedias;
import java.util.Scanner;
/**
*
-
@author Usuario
*/
public class ControleNotasMedias {/**
-
@param args the command line arguments
*/
public static void main(String[] args) {Turma t =
new Turma();
Aluno a =new Aluno();Scanner sc =
new Scanner(System.in);for ({int i = 0; i < t.alunos.length; i++)double media; System.out.println("Digite o nome do aluno " + i + ":"); a.setNome(sc.nextLine()); System.out.println("RA:"); a.setRa(sc.nextInt()); System.out.println("Digite a nota 1 do aluno " + a.getNome() + ":"); a.setNota1(sc.nextDouble()); System.out.println("Digite a nota 2 do aluno " + a.getNome() + ":"); a.setNota2(sc.nextDouble()); System.out.println("Digite a nota 3 do aluno " + a.getNome() + ":"); a.setNota3(sc.nextDouble()); System.out.println("Digite a nota 4 do aluno " + a.getNome() + ":"); a.setNota4(sc.nextDouble()); System.out.println("A média do aluno " + a.getNome() + " é:"); System.out.println(a.getMedia()); sc.nextLine();
}
System.out.println(“A média de notas da turma é:”);
System.out.println(t.mediaTurma());
-
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package controlenotasmedias;
/**
*
-
@author Usuario
*/
public class Aluno {private String nome; private int ra; private double nota1; private double nota2; private double nota3; private double nota4;
public double getMedia(){
double media; media = (getNota1() + getNota2() + getNota3() + getNota4())/4; return(media);
}
/**
* @return the nome
*/
public String getNome() {
return nome;
}
/**
* @param nome the nome to set
*/
public void setNome(String nome) {
this.nome = nome;
}
/**
* @return the ra
*/
public int getRa() {
return ra;
}
/**
* @param ra the ra to set
*/
public void setRa(int ra) {
this.ra = ra;
}
/**
* @return the nota1
*/
public double getNota1() {
return nota1;
}
/**
* @param nota1 the nota1 to set
*/
public void setNota1(double nota1) {
this.nota1 = nota1;
}
/**
* @return the nota2
*/
public double getNota2() {
return nota2;
}
/**
* @param nota2 the nota2 to set
*/
public void setNota2(double nota2) {
this.nota2 = nota2;
}
/**
* @return the nota3
*/
public double getNota3() {
return nota3;
}
/**
* @param nota3 the nota3 to set
*/
public void setNota3(double nota3) {
this.nota3 = nota3;
}
/**
* @return the nota4
*/
public double getNota4() {
return nota4;
}
/**
* @param nota4 the nota4 to set
*/
public void setNota4(double nota4) {
this.nota4 = nota4;
}
}
/*
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
*/
package controlenotasmedias;
/**
*
-
@author Usuario
*/
public class Turma {protected Aluno[] alunos;
public Turma() {
alunos = new Aluno[5]; Aluno a = new Aluno(); for (int i = 0; i < alunos.length; i++) { alunos[i]=new Aluno(); alunos[i].
} } public double mediaTurma(){
double mediaTurma; double[] media = new double[5]; for (int i = 0; i < media.length; i++) { media[i] = (alunos[i].getNota1() + alunos[i].getNota2() + alunos[i].getNota3() + alunos[i].getNota4())/4; } mediaTurma = (media[0] + media[1] + media[2] + media[3] + media[4])/5; return mediaTurma;
}
private String get(String nome) { throw new UnsupportedOperationException(“Not supported yet.”); //To change body of generated methods, choose Tools | Templates. } }

