2
Assuming that I have a list chained Students, where one must register name and note, however this same student may contain more than one note. In my logic, he only registers a student with a single grade, as can be seen in the code below:
Class responsible for the Getters and Data Setters (the given "number" would be the identified of each student)
public class Lista {
private String nome;
private Lista prox;
private int numero;
private double nota;
public double getNota() {
return nota;
}
public void setNota(double nota) {
this.nota = nota;
}
public int getNumero() {
return numero;
}
public void setNumero(int numero) {
this.numero = numero;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Lista getProx() {
return prox;
}
public void setProx(Lista prox) {
this.prox = prox;
}
}
Class responsible for adding methods and later other functions
public class Aluno {
Lista topo;
Lista ultimo;
int numero = 1;
public String pilharAluno(String nome, double nota) {
Lista novo = new Lista();
novo.setNome(nome);
novo.setNumero(this.numero);
novo.setNota(nota);
this.numero++;
if (topo == null) {
topo = novo;
ultimo = novo;
novo.setProx(null);
} else {
novo.setProx(topo);
topo = novo;
}
return "Aluno cadastrado";
}
}
Already tried to connect a list of grades in each student?
– ptkato
@Patrick I thought of this logic, but I can’t implement it.
– Dan Lucio Prada
I suggest you use C to work with data structures, because theoretically they are not object oriented but memory addresses!
– AndersonBS
@Danlucioprada, you need to implement the chained list, is that it? You can’t use
LinkedList
java? It wasn’t clear to me whether you just need to solve the problem you described or need to, in addition, implement the chained list.– Dherik
@Dherik needs to implement a chained list for student registration, the problem is in the fact that each student can contain more than one grade. (no native Java functions, all in the form of manually written data structures)
– Dan Lucio Prada
@Danlucioprate you will need to create a new class with exactly the same functions as the List class but with different attributes. I recommend using inheritance in this case to not repeat code. If this comment does not help you understand, answer me that tomorrow I will draft a complete reply for you.
– Elyel Rubens da Rosa