Ask Experts Questions for FREE Help !
Ask
    JBing14's Avatar
    JBing14 Posts: 1, Reputation: 1
    New Member
     
    #1

    Jul 10, 2014, 10:54 AM
    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);
    }
    }

Check out some similar questions!

How to store Scanner data in string in java? [ 0 Answers ]

I am new to java, currently I am working on a program regarding networking. My program compiles without error. I have placed 3 checks in my program. It passes through check 1 but does not reach 2. I want string player2msg to store whatever data comes from scanner fromServer. I expected...

Having difficulty with Java String [ 1 Answers ]

Can someone please me how I can write a Java code to transform the quantity 6 As into the string AAAAAA. I'm trying this, but it does not work: public class Letters { public static void main (String args) { String words=" "; String numberofwords="A"; int wordcount=6;

Convert arraylist to an array of arraylist! [ 0 Answers ]

I do have an ArrayList and I want to convert it to an array of arrayList. I have a class X that has an ArrayList. And In the main class , I have an ArrayList that has many X objects. I want to create a new Array of ArrayList Y that has the element of the ArrayList from X in my ArrayList. How...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.