I am trying to create a program that will allow users to enter a list of names. And then the program will pull from the ArrayList randomly and pull each name one at a time until all names have been used. I have the scanner part completed as seen below:
public class Auction
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
ArrayList<String> names = new ArrayList<String> ();
char quit = 'Y';
String playername = null;
while (quit == 'Y')
{
System.out.println("\nPlayer Name:");
playername = scan.next();
names.add (playername);
System.out.print("Enter Another Name? (Y/N) \n");
String word = scan.next();
word = word.toUpperCase();
quit = word.charAt(0);
}
}
}
I have another class where I tried to complete the random generation with no success. There doesn't appear to be any errors but it's not working either. I know I am way off on the "random without replacing" part but I was just trying to get it to work before I moved on. I'm not sure if I am even referencing the ArrayList from the other Auction Class. Like a lot of others, I am new to Java so be gentle. I have spent a week on this which should probably have taken me a few hours. I appreciate your help.
public class Draft
{
Random randomGenerator;
ArrayList<String> names;
String randName() {
int index = randomGenerator.nextInt(names.size());
System.out.println("Next on the Block" + names.get(index));
return names.get(index);
}
}