Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.*; public class DraftOrder { public static void printList(Strin

ID: 3731106 • Letter: I

Question

import java.util.*;

public class DraftOrder {

public static void printList(String[] array) {

for (int i = 0; i < array.length; i++) {

System.out.println((i + 1) + ") " + array[i]);

}

}

public static void shuffle(String[] array) {

Random rand = new Random();

for (int i = array.length - 1; i >= 0; --i) {

int j = rand.nextInt(i + 1);

String temp = array[i];

array[i] = array[j];

array[j] = temp;

}

}

public static void main(String[] args) {

Scanner kb = new Scanner(System.in);

System.out.print("Enter league size: ");

int length = kb.nextInt();

System.out.println("Enter " + length + " names");

String[] names = new String[length];

for (int index = 0; index < names.length; index++) {

names[index] = kb.next();

}

System.out.println(" Original List");

System.out.println("----------------------");

printList(names);

shuffle(names);

System.out.println("----------------------");

System.out.println(" Draft Order");

System.out.println("----------------------");

printList(names);

System.out.print(" Enter number of divisions: ");

int divisions = kb.nextInt();

int teams = names.length / divisions;

// System.out.print("Enter number of teams per division: ");

// int teams = kb.nextInt();

shuffle(names);

for (int i = 0; i < divisions; i++) {

System.out.println("------------------------------");

System.out.println(" Division " + (i + 1) + ": ");

System.out.println("------------------------------");

for (int j = i * teams; j < ((i + 1) * teams); j++) {

System.out.println(names[j]);

}

}

kb.close();

}

}

Is there a way to pause in between names after they are shuffled. Just don't want all the names to print out at once maybe like a 15 second pause in between each name.

Explanation / Answer

For pausing between printing statments please use Thread.sleep(milllisec); which will stop the flow for specified amount of time. Please find the below syntax. sleep() will throw the checked exception we need to keep this statment in try catch

try{

Thread.sleep(1500);

}

catch(Excpeption e){}

import java.util.*;

public class DraftOrder {

public static void printList(String[] array) {

for (int i = 0; i < array.length; i++) {

System.out.println((i + 1) + ") " + array[i]);

try{

Thread.sleep(1500);

}

catch(Exception e){}

}

}

public static void shuffle(String[] array) {

Random rand = new Random();

for (int i = array.length - 1; i >= 0; --i) {

int j = rand.nextInt(i + 1);

String temp = array[i];

array[i] = array[j];

array[j] = temp;

}

}

public static void main(String[] args) {

Scanner kb = new Scanner(System.in);

System.out.print("Enter league size: ");

int length = kb.nextInt();

System.out.println("Enter " + length + " names");

String[] names = new String[length];

for (int index = 0; index < names.length; index++) {

names[index] = kb.next();

}

System.out.println(" Original List");

System.out.println("----------------------");

printList(names);

shuffle(names);

System.out.println("----------------------");

System.out.println(" Draft Order");

System.out.println("----------------------");

printList(names);

System.out.print(" Enter number of divisions: ");

int divisions = kb.nextInt();

int teams = names.length / divisions;

// System.out.print("Enter number of teams per division: ");

// int teams = kb.nextInt();

shuffle(names);

for (int i = 0; i < divisions; i++) {

System.out.println("------------------------------");

System.out.println(" Division " + (i + 1) + ": ");

System.out.println("------------------------------");

for (int j = i * teams; j < ((i + 1) * teams); j++) {

System.out.println(names[j]);

}

}

kb.close();

}

}