Random sorting divided in lists

Discussion in 'Java' started by ebotelho, Aug 3, 2011.

  1. ebotelho

    ebotelho

    Joined:
    Aug 3, 2011
    Messages:
    1
    Hello, I'm trapped in a situation where I can't go any further. I have a list of names of which I want to divide into lists after being randomly sorted. For example:
    Names: John, Paul, Jenna, Izabela; of which I choose to divide into four lists. That should result into something like this:

    List 1:
    Jenna

    List 2:
    Paul

    List 3:
    John

    List 4:
    Izabela

    Of course, there will be a list of names. I am far from an experienced developer and I use an auxiliary class to help me do some stuff. My progress so far is this:


    public static void sortNames() {
    FILE arquivo = new FILE(FILE.INPUT, "nomes.txt");
    String [] lista = new String [countNames()];
    String linha;
    String temp;

    linha = arquivo.readln();
    for (int i=0; i<countNames(); i++) {
    lista = linha;
    linha = arquivo.readln();
    }
    IO.println();

    //randomizar aqui
    Collections.shuffle(Arrays.asList(lista));

    int numero = IO.readint("Quantas listas? ");
    IO.println();
    int qtd = countNames()/numero;
    if (qtd < 1) {
    IO.println("Nomes insuficientes para tantas listas.");
    }
    else {
    int p=0;
    IO.println("Distribuindo "+countNames()+" em "+numero+" listas.");
    IO.println("SerĂ£o "+qtd+" nomes por lista.");
    IO.pause("Pressione ENTER");
    for (int a=0; a<numero; a++) {
    IO.println("Lista "+(a+1));
    for (int i=0; i<qtd; i++) {
    IO.println(lista);
    }
    IO.println();
    }

    }
    }

    And it is in portuguese, I suppose, though, you can understand pretty much of it.
    The critical point is in bold. Any suggestions to make this work? Thanks a bunch.
    ebotelho, Aug 3, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JustSomeGuy

    Sorting lists of lists...

    JustSomeGuy, Jun 17, 2004, in forum: C++
    Replies:
    0
    Views:
    305
    JustSomeGuy
    Jun 17, 2004
  2. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    384
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  3. globalrev
    Replies:
    4
    Views:
    742
    Gabriel Genellina
    Apr 20, 2008
  4. Chris Weisiger

    Help with sorting lists of lists

    Chris Weisiger, Oct 14, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    119
    Tad McClellan
    Oct 14, 2004
  5. VK
    Replies:
    15
    Views:
    1,116
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page