Hello, can someone help me with this problem? I would like to fully understand the handling of the linked lists and I stayed with this example. Make an application that allows to generate different lists related to a specific community of neighbors. For this we need to store the data of the different neighbors: name, surnames, block, door, monthly fee and the total amount owed to the community. The application will allow the following listings: - Alphabetically organized list of all the neighbors of the community. - List of neighbors ordered decreasingly by amount they owe. - List of neighbors belonging to a certain block. - List of neighbors ordered by the amount of the monthly fee they must pay.
I have done the first section but I do not know if I am doing it the right way. I appreciate the help.
Vecino.java
public class Vecino implements Comparable <Vecino> {
private String nombre;
private String apellidos;
private int bloque;
private char puerta;
private double cuotaMensual;
private double importeDebe;
Vecino(String nombre, String apellidos, int bloque, char puerta, double cuotaMensual, double importeDebe){
this.nombre = nombre;
this.apellidos = apellidos;
this.bloque = bloque;
this.puerta = puerta;
this.cuotaMensual = cuotaMensual;
this.importeDebe = importeDebe;
}
Vecino(){
}
/**
* @return the nombre
*/
public String getNombre() {
return nombre;
}
/**
* @param nombre the nombre to set
*/
public void setNombre(String nombre) {
this.nombre = nombre;
}
/**
* @return the apellidos
*/
public String getApellidos() {
return apellidos;
}
/**
* @param apellidos the apellidos to set
*/
public void setApellidos(String apellidos) {
this.apellidos = apellidos;
}
/**
* @return the bloque
*/
public int getBloque() {
return bloque;
}
/**
* @param bloque the bloque to set
*/
public void setBloque(int bloque) {
this.bloque = bloque;
}
/**
* @return the puerta
*/
public char getPuerta() {
return puerta;
}
/**
* @param puerta the puerta to set
*/
public void setPuerta(char puerta) {
this.puerta = puerta;
}
/**
* @return the cuotaMensual
*/
public double getCuotaMensual() {
return cuotaMensual;
}
/**
* @param cuotaMensual the cuotaMensual to set
*/
public void setCuotaMensual(double cuotaMensual) {
this.cuotaMensual = cuotaMensual;
}
/**
* @return the importeDebe
*/
public double getImporteDebe() {
return importeDebe;
}
/**
* @param importeDebe the importeDebe to set
*/
public void setImporteDebe(double importeDebe) {
this.importeDebe = importeDebe;
}
@Override
public int compareTo(Vecino o) {
return this.nombre.compareTo(o.getNombre()); //To change body of generated methods, choose Tools | Templates.
}
}
Main.java
public class Main {
LinkedList<Vecino> vecinos = new LinkedList<>();
public void mostrarTodosVecinos(LinkedList<Vecino> vecinos){
System.out.println("Listado de vecinos ordenados alfabéticamente: ");
Collections.sort(vecinos);
for (Vecino vecino : vecinos) {
System.out.println("Nombre: "+vecino.getNombre()+" "+vecino.getApellidos()+"\n"+
"Bloque: "+vecino.getBloque()+"\n"+
"Puerta: "+vecino.getPuerta()+"\n"+
"Cuota mensual: "+vecino.getCuotaMensual()+"\n"+
"Importe que debe: "+vecino.getImporteDebe()+"\n");
}
}
public static void main(String[] args) {
Main prueba = new Main();
LinkedList<Vecino> vecinos = new LinkedList<>();
Vecino veci = new Vecino("Jaime","Weirk",2,'A',20,40);
Vecino veci1 = new Vecino("Laura","Gil",1,'C',20,20);
Vecino veci2 = new Vecino("Mike","Aton",4,'B',20,60);
Vecino veci3 = new Vecino("Billy","Willy",5,'D',20,10);
vecinos.add(veci);
vecinos.add(veci1);
vecinos.add(veci2);
vecinos.add(veci3);
prueba.mostrarTodosVecinos(vecinos);
}
}