Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java Class

  • 21-11-2014 1:01pm
    #1
    Banned (with Prison Access) Posts: 6


    Hi guys,

    I'm doing a World Cup Group Draw Java Program and am having trouble with it. I want to draw teams and place them into random groups. It is taxing.

    Here is the code.

    Java Code:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    package TheWorldCup;
    //import java.util.Array;
    import java.util.Random;
    import java.util.Scanner;

    public class WorldCup2014 {

    public static void main(String args[]){


    String[][] WCArray = {{"Australia", "Iran", "China", "Saudi Arabia", "USA","Mexico","Canada","Honduras", "South Africa", "Nigeria",
    "Morocco", "Ghana", "Rwanda", "Brazil", "Argentina", "Colombia", "Ecuador", "Chile", "England", "Spain","Germany","France",
    "Portugal","Scotland", "Republic of Ireland", "Sweden", "Italy", "Bosnia","Belguim", "Hungary", "Greece", "Bolivia" }};

    String[][] WCGroup = {{"Group One", "Group Two", "Group Three", "Group Four", "Group Five",
    "Group Six", "Group Seven", "Group Eight"}};



    Random random = new Random();

    Scanner WCTeam = new Scanner(System.in);

    System.out.println("There are 8 possible groups");
    System.out.println("Enter a Team to be drawn");
    String Team = WCTeam.nextLine();

    for(int i=0; i<7; i++){
    System.out.println("Their group is:" +WCGroup );
    }

    // for(int j=0; j<31; j++){
    // System.out.println("Team is: " + j);
    // }





    }
    }

    What if anything else do i need to do?


Comments

  • Moderators, Computer Games Moderators, Technology & Internet Moderators Posts: 19,241 Mod ✭✭✭✭L.Jenkins


    Firstly, you don't need to store the Team names and Group names in a 2d Array, you can save the output of the random group choice to a 2d Array instead and use an ordinary Array for the Names if you wish. I see you initialized the Random class but don't actually use it.

    Random rn = new Random(); int answer = rn.nextInt(8) + 1;

    Will do the trick as you have 8 groups.

    You'll need a nested for loop or a method of traversing to
    the next row in the 2d Array if your app places more than one
    team in a group.

    You'll definitely need the 2d Array if you want to print out the
    contents of the Array.


  • Registered Users, Registered Users 2 Posts: 6,240 ✭✭✭hussey


    I don't think you really understand arrays:
    e.g. String[][] WCGroup = {{"Group One", "Group Two", "Group Three", "Group Four", "Group Five",
    "Group Six", "Group Seven", "Group Eight"}};
    is actually a [1][8] array ... why, what do you want to achieve?
    Have a think about what is it you want to achieve rather than try code first, try talking out loud and telling yourself what the program should do.
    Or even better would be to take a TDD (test driven development approach) and test & build one area at a time.
    e.g. 1) build a single team to be drawn and assign to group
    (what is a group? an array of 4 objects? ... how many groups? 8 ... so how should your 2d array be structured)
    2) draw team twice then display error
    3) draw 2nd team and assign to same group
    4) draw 3rd & 4 same group
    5) draw 5th to same group .... what should happen?????
    6) build on these test cases and introduce random assignments
    ....
    N) your last test should be a complete test.


Advertisement