Random sorting divided in lists

Joined
Aug 3, 2011
Messages
1
Reaction score
0
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top