Results 1 to 6 of 6
  1. #1
    saziz94 is offline Member
    Join Date
    Jul 2009
    Posts
    9
    Rep Power
    0

    Default Java Project ..... Advise

    Hi guys,

    Currently, I'm working on a project to design a Framework for Managing any Sport Game.

    So, one of the features the project should accomplished is to make a function to divide teams to groups.
    e.g.
    World Cup games
    After entering the teams as an Object, divide them to groups. (suppose the number of groups entered by the USER)

    I'm trying to find a way to store the teams in different groups and their match result.

    I used a HashMap, but it doesn't work especially when I look up for the match result for a specified games


    Could someone advise me.
    Thank you,

  2. #2
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Smile

    Hashmap seems to be the correct data structure for storing the match results. But, it gives me a feeling that you are trying to store too many related things in a single hashmap.

    Use different hashmaps for different things, like: for teams within a group, matches and results, etc. Then associate these structures as they are associated in real life.

    Otherwise, list down the exact requirement for more details.

  3. #3
    saziz94 is offline Member
    Join Date
    Jul 2009
    Posts
    9
    Rep Power
    0

    Default

    Hi, Thank you for your advise and I'm sorry for late responding.

    What I'm trying to do is to let the user Enter Teams by using Team class.
    Also, I made another class "Games" to make a group of these teams and to store games data. Also, it generate the matches among these teams.

    I initialize a HashMap to store Games data;

    Map<Group,Team> _data = new HashMap<Group,Team>();

    the problem when I enter another Team the previous Team will be deleted.

    _data.put("A","Brazil");
    _data.put("A","Spain");

    I can't get Brazil in the HashMap any more.

    About the Games Result
    I don't know how to declare the HashMap for the game results.
    e.g.
    Suppose the result game of Brazil vs Spain is 2-2
    the declaration of HashMap is ....= new HashMap<Key, Value>(); << Right
    So,
    is it possible to store the combination of Brazil and Spain as HashMap Key
    also, the result 2-2 as HashMap Value.

    Your cooperation is appreciated.

  4. #4
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    A hashmap only allows one value per key. If you want multiple entries for the same key, use another collection as the value...for example

    Java Code:
    Map<Group,Set<Team>> _data = new HashMap<Group,HashSet<Team>>();
    ...now add Brazil and Spain to the same set, and use that set as the value for the key "A".

  5. #5
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Smile

    Saziz,

    I suggest you to see Hashmap api docs before using it.

    regarding your particular problem, you should have only 1 team as the winner for a particular match, e.g. For Match 'A' -- Winner Brazil
    Match 'B' -- Winner Argentina and so on.....

    For every result your key should change (actually you are keeping it same, which is wrong).

    Read the docs and let me know if you need any help on design.

  6. #6
    saziz94 is offline Member
    Join Date
    Jul 2009
    Posts
    9
    Rep Power
    0

Similar Threads

  1. Advise the Library, please
    By tmlder in forum New To Java
    Replies: 0
    Last Post: 10-11-2010, 09:53 AM
  2. need an advise please
    By EBBOOO in forum New To Java
    Replies: 29
    Last Post: 07-25-2010, 09:21 PM
  3. Some advise please!!!
    By PVL268 in forum New To Java
    Replies: 2
    Last Post: 04-17-2009, 09:36 AM
  4. need advise...
    By chkm8 in forum AWT / Swing
    Replies: 4
    Last Post: 02-10-2009, 05:57 AM
  5. give me a advise
    By sireesha in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 01:38 AM

Posting Permissions

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