Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Random Generate String from ArrayList without replacement in JAVA (https://www.askmehelpdesk.com/showthread.php?t=796430)

  • Jul 10, 2014, 10:54 AM
    JBing14
    Random Generate String from ArrayList without replacement in JAVA
    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.The auction class by itself i working fine. Problem is in the Draft class. I want to take the names that the user enters as the ArrayList and then randomly generate them one at a time without repetition until all have been generated. It's basically a name auction. The list of names go in. Then, say with each keystroke (spacebar) they will randomly be called to bid on, one by one, until all have been bid on. This program just takes the names entered and randomly generates them one at a time so the audience can bid on them. I know I do not have the "keystroke" part at all. I was just trying to get it to work and spit out a random name from the list. I am new to Java. So if you use a lot of terms I will not understand. I am a "show me" learner. If you show me exactly what needs to be done I will be able to understand it going forward. I appreciate your help greatly.

    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);
    }
    }
    }
    public class Draft
    {

    private List<String> names;


    public Draft(List<String> names) { this.names = names; }
    Collections.shuffle(names);
    Iterator<String> it = names.iterator();


    while (it.hasNext()) {
    String names = it.next();


    it.remove();


    System.out.println("Next on the block" + names);
    }
    }

  • All times are GMT -7. The time now is 07:10 AM.