Arrangements of objects as compare [duplicate]

0

I would like to know how I can make my method print, print the object. and I run it in the bubble method, I also add my test code. Because what I print is

  

ordenamientos.Persona@15db9742 - ordenamientos.Persona@6d06d69c - ordenamientos.Persona@7852e922 - ordenamientos.Persona@4e25154f - ordenamientos.Persona@70dea4e -

public class Ordenamiento <E extends Comparable <E>> {
 private E elementos[];

public Ordenamiento(E [] arreglo){
    elementos =  arreglo;
}

public void imprimir() {
    for (int i = 0; i < elementos.length; i++) {
        System.out.print(elementos[i].getClass()+ " - ");
        if (i % 5 == 4) {
            System.out.println();
        }
    }
}

public void burbuja() {
    for (int i = 1; i < elementos.length; i++) {
        for (int j = 0; j < elementos.length - i; j++) {

            if ( (elementos[j].compareTo(elementos[j + 1])) < 0) {
                E aux = elementos[j];
                elementos[j] = elementos[j + 1];
                elementos[j + 1] = aux;

            }
            imprimir();
        }
    }
} 

TEST CLASS

public class TestOrdenamientoG {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
   Persona[] per = new Persona[5];

    Persona p0 = new Persona("Miguel");
    Persona p1 = new Persona("Vanessa");
    Persona p2 = new Persona("David");
    Persona p3 = new Persona("Jessica");
    Persona p4 = new Persona("Brenda");

    per[0] = p0;
    per[1] = p1;
    per[2] = p2;
    per[3] = p3;
    per[4] = p4;

    Ordenamiento or = new Ordenamiento(per);
    or.burbuja();

    System.out.println(per[0].getNombre());
    System.out.println(per[1].getNombre());
    System.out.println(per[2].getNombre());
    System.out.println(per[3].getNombre());
    System.out.println(per[4].getNombre());
}

}
    
asked by vngm19 15.09.2018 в 06:26
source

1 answer

0

I see that it can affect you:

  • In the print method:

    System.out.print (elements [i] .getClass () + "-");

  • Remove the .getClass() , that method gives you the name of the class of the object, look for some method of the person class that gives you the name and use it there.

    Greetings.

        
    answered by 15.09.2018 / 06:52
    source