0
I need to implement a data structure queue, with objects, being RA and student name but I’m not able to evolve, a queue with only integers I get good, already this will not even.
I think I’m getting it on main, I’m not knowing how to call the methods or how to instantiate the classes.
Go as far as I can go:
public class Aluno implements Comparable<Aluno> {
private Integer RA;
private String nome;
public Aluno (Integer RA, String nome) {
this.RA = RA;
this.nome = nome;
}
public Integer getRA(){
return this.RA;
}
public void setRA(Integer RA) {
this.RA = RA;
}
public String getNome() {
return this.nome;
}
public void setNome(String nome) {
this.nome = nome;
}
@Override
public String toString() {
return this.RA+" - "+this.nome;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!Aluno.class.isAssignableFrom(obj.getClass())) {
return false;
}
final Aluno aluno = (Aluno) obj;
return this.RA.equals(aluno.getRA());
}
@Override
public int compareTo(Aluno o) {
Integer compare = this.RA.compareTo(o.getRA());
if(compare == 0){
compare = this.nome.compareTo(o.getNome());
}
return compare;
}
}
class Fila
import java.util.List;
import java.util.Vector;
public class Fila {
private List<Aluno> items = new LinkedList<Aluno>;
public Fila() {
this.items = new Vector<>();
}
public void enfilera(Aluno aluno) {
this.items.add(Aluno);
}
public Aluno desenfilera() {
return this.items.remove(0);
}
public boolean eVazio() {
return this.items.size() == 0;
}
public int tamanho(){
return 0;
}
public List<Aluno> getItems(){
return this.items;
}
}
Main:
class Main {
public static void main(String[] args) {
Fila fila = new Fila();
Aluno aluno = new Aluno();
fila.insere(aluno);
}
}
Have you tried using Arraylist instead of List to store students in the queue?
– Lucas Rufino
Good if you are allowed to use the Java Collection API, use the Queue interface and its Priorityqueue implementation
– Viktor Hugo