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

Trying to get the size of a list and names on the list input by a user and then

ID: 3723098 • Letter: T

Question

Trying to get the size of a list and names on the list input by a user and then randomize the list in a new random order. Below is the code I have but keep getting an error. Also would like to use the GUI built within Java but not sure how to do that. Any help would be greatly appreciated.

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];

names[length] = kb.nextLine();

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

{

names[index] = kb.nextLine();

}

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

printList(names);

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

shuffle(names);

  

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

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

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

printList(names);

Explanation / Answer

import java.util.*; public class DraftOrder { public static void printList(String[] array) { for (int i = 0; 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]; //names[length] = kb.nextLine(); for (int index = 0; index