How to record a student's grades using arrayList

0

I need to add notes to certain students (each student has several notes and each note belongs to a subject), however as I am using arrayList and I have little knowledge in java I am well lost in passing parameters and how to add new values using function registrarNota .

Someone could explain what I should do.

PS (I can not use Extends)

Student class:

package auladia24;

import java.util.ArrayList;

public class Aluno {
    private String nome;
    private String ra;
    private ArrayList<Nota> notas = new ArrayList(); // tipo da array e o nome da array

    public Aluno(String nome, String ra){
        this.nome = nome;
        this.ra = ra;
    }

    public String getNome (){
        return this.nome;
    }

    public String getRa(){
        return this.ra;
    }

    public ArrayList getNotas(){
        return this.notas;
    }

    public Nota registrarNota(double valor, Disciplina nomeDisciplina){

    }
}

Class Note:

package auladia24;

public class Nota {
    private double valor ;
    private Disciplina nomeDisciplica;

    public void  nota (double nota, Disciplina nomeDisciplina){
        this.valor = valor;    
        this.nomeDisciplica = nomeDisciplica;
    }

    public double getNota(){
        return this.valor;
    }

    public Disciplina getDisciplina(){
        return this.nomeDisciplica;
    }

}

Class Discipline:

package auladia24;

public class Disciplina {
    private String nome;

    public Disciplina (String nome){
        this.nome = nome;
    }

    public String getNome(){
        return this.nome;
    }
}
    
asked by anonymous 27.05.2017 / 20:49

1 answer

1

So I understand you need to use the registrarNota method right? it asks for a double and a Discipline object.

public Nota registrarNota(double valor, Disciplina nomeDisciplina)
{
    //primeiro checa se ja existe a nota
    for(Nota n : notas)
    { 
        if(n.getDisciplina().getNome().equals(objetoDisciplina.getNome()))
        {
            n.setNota(valor); 
            return n;
        }
    }
    Nota n = new Nota(valor, nomeDisciplina); //cria a nova nota
    notas.add(n); //adiciona ela no arraylist
    return n; //retorna a nota criada
}

It is necessary to add method setNota to class Nota

public void setNota(double valor)
{
    this.valor = valor
}

To call it would simply be aluno.registrarNota(nota, objetoDisciplina);

    
27.05.2017 / 22:12