Results 1 to 6 of 6
  1. #1
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Cool Add to a group and show the group x 8 times

    Hey guys,

    I have this code:

    Java Code:
    package TheWorldCup;
    
    import java.util.ArrayList;
    import java.util.*;
    
    public class WorldCup2014{
    
    public static void main(String args[]){
    	
    	ArrayList<String> WorldCupTeams = new ArrayList<>();
    	Scanner Russia2018 = new Scanner(System.in);
    	Random randGroup = new Random();
    	
    	WorldCupTeams.add("Australia");WorldCupTeams.add("Canada");
    	WorldCupTeams.add("China");WorldCupTeams.add("Germany");
    	WorldCupTeams.add("Qatar");WorldCupTeams.add("France");
    	WorldCupTeams.add("Iran");WorldCupTeams.add("Spain");
    	WorldCupTeams.add("Cameroon");WorldCupTeams.add("Holland");
    	WorldCupTeams.add("Morocco");WorldCupTeams.add("Ireland");
    	WorldCupTeams.add("South Africa");WorldCupTeams.add("England");
    	WorldCupTeams.add("Ghana");WorldCupTeams.add("Portugal");
    	WorldCupTeams.add("Nigeria");WorldCupTeams.add("Romania");
    	WorldCupTeams.add("Brazil");WorldCupTeams.add("Russia");
    	WorldCupTeams.add("Argentina");WorldCupTeams.add("Serbia");
    	WorldCupTeams.add("Colombia");WorldCupTeams.add("Switzerland");
    	WorldCupTeams.add("Ecuador");WorldCupTeams.add("Sweden");
    	WorldCupTeams.add("Chile");WorldCupTeams.add("Denmark");
    	WorldCupTeams.add("USA");WorldCupTeams.add("Japan");
    	WorldCupTeams.add("Mexico");WorldCupTeams.add("Curacao");
    
    	ArrayList<String> WorldCupGroups = new ArrayList<>();
    	
    	WorldCupGroups.add("Group One");WorldCupGroups.add("Group Five");
    	WorldCupGroups.add("Group Two");WorldCupGroups.add("Group Six");
    	WorldCupGroups.add("Group Three");WorldCupGroups.add("Group Seven");
    	WorldCupGroups.add("Group Four");WorldCupGroups.add("Group Eight");
    	
    	System.out.println("Welcome to the World Cup Russia 2018");
    	System.out.println("How will the minoes of Curacao get on this Year");
    	System.out.println("Lets begin the draw");
    	
    	System.out.println("Pick the first team and start the draw");
    	String Team = Russia2018.nextLine();
    	System.out.println("The first team out is:" +Team);
    	
    	for(int i =0; i <7; i++ ){
    		System.out.println("Their group is:"+WorldCupGroups.remove(0));
    		
    	}
    	
    		System.out.println("Group is: "+"\n"+Team);
    	}
    		
    		
    
    
    }
    What it is doing is printing the team name and all eight groups and showing the group is: team name under.

    I want it to print out the team name, put it into a group and print out the group. Once 4 teams in a group, close that group off, do this until all groups are filled.

    How can I do this?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,143
    Rep Power
    14

    Default Re: Add to a group and show the group x 8 times

    It's hard to answer general "how do I do this" type questions other than by pointing you to google and the basic tutorials. There are a million different ways to do any particular task, and the whole point of the homework is to teach you how to investigate those different ways and settle on the approach that makes the most sense to you.

    How would you do this without a computer? How would you associate teams with a group? How would you determine when a group was full? Write down what you would do, in English, and that will be the algorithm that you can start thinking about implementing in code.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Add to a group and show the group x 8 times

    Basically this is a continuation of this previous thread:

    http://www.java-forums.org/new-java/...roup-draw.html
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    aboyse1990 is offline Member
    Join Date
    Nov 2014
    Posts
    61
    Rep Power
    0

    Default Re: Add to a group and show the group x 8 times

    Sort of but, i kind of have it working.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Add to a group and show the group x 8 times

    You keep saying "eight groups." Did you want to do this for all eight?

    Java Code:
    for(int i =0; i <7; i++ ) {
         System.out.println("Their group is:"+WorldCupGroups.remove(0));
    }
    If so, 7 should be 8 or change < to <=. Typically, this is the idiom that is used:

    Java Code:
    for (int j = 0; j < WordCupGroups.size(); j++) {
       // do something
    }
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Add to a group and show the group x 8 times

    team name, put it into a group and print out the group.
    A Map might work here with key = group name, value = arraylist of teams. Remove the key from the Map when the list is full.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Show group header above each displayed table
    By maas in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-28-2014, 09:26 AM
  2. I Think we should be a group !
    By Po Nio in forum New To Java
    Replies: 11
    Last Post: 08-23-2014, 12:34 PM
  3. New To The Group
    By javarishi in forum Introductions
    Replies: 5
    Last Post: 04-10-2008, 04:34 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •