Assuming I have a linked list of Students, where you must register name and note, however this same student may contain more than one note. In my logic, it only registers a student with a single note, as you can see in the code below:
Class responsible for Getters and Data Setters (the given "number" would be the identified number 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 methods of adding and then 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";
}
}