1 Replies - 1323 Views - Last Post: 26 November 2007 - 10:03 AM Rate Topic: -----

#1 Starmage187   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-November 07

How to separate input from a list into groups using a random starting

Posted 25 November 2007 - 12:34 PM

Hello. I should, before I go any further, state the obvious: I'm a bad programmer. I can do a little BASIC, a little Fortran, and some ASP, but for the most part I suck. And, as you can imagine, Java is kicking my can.

That being stated, here is my problem. I have a homework assignment in which the goal is to take an indeterminate number of names in a list from a text document, get a random number between 1 and four, take four names in sequence from the list and assign them to groups based on numbers one through four. Then get a new random number and start on the next set.

Example. Say my first random number comes up 3. The first four names on my list are Sally, Tom, Jane, and Harry. The outcome would need to be like this:

Team Name
3 Sally
4 Tom
1 Jane
2 Harry


Then, generate a new random number, grab the next four names, and do it again until the end of the list.


Now, I can get the list into the program. And I can generate the random numbers, but for the life of me I can't figure out how in the hell to get them to do the assignments. I've been staring at this problem for the better part of the past week, and I just don't know where to start on the grouping.

Could some one help me? I know this is kind of rambling, but I hate having to ask for help in the first place, and so I want anyone looking at this to have the most information possible. Thank you for your time.

P.S. There is no code posted in this question yet, as the issue isn't really with the code but me being too retarded to see how to do this. If some one suggests some one, I'll add it to my input and number generating code and post it in here.

Is This A Good Question/Topic? 0
  • +

Replies To: How to separate input from a list into groups using a random starting

#2 oubless   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 28-May 07

Re: How to separate input from a list into groups using a random starting

Posted 26 November 2007 - 10:03 AM

View PostStarmage187, on 25 Nov, 2007 - 12:34 PM, said:

Example. Say my first random number comes up 3. The first four names on my list are Sally, Tom, Jane, and Harry. The outcome would need to be like this:

Team Name
3 Sally
4 Tom
1 Jane
2 Harry


Then, generate a new random number, grab the next four names, and do it again until the end of the list.


An idea:

1.Read the file and add to a list, let's call it
 java.util.List<String> allNames = new java.util.LinkedList<String>();

so we have an ordered list of names [Sally, Tom, Jane, Harry, Peter, George, Ann, Someone]

2. Prepare List ( called groups for example ) containing 4 empty Lists ( the groups 0-3 , add 1 to find the group number )
List<List<String>> groups = new ... 


3. Take Iterator namesIterator from allNames and until its method hasNext() == true:

3.1 Generate random number i ( 0-3 )

3.2 Repeat 4 times the following:
3.2.1 if( namesIterator.hasNext() ) groups.get( i ).add( namesIterator.next() )
3.2.2 i++;


I hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1