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.
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.