Page 1 of 2 12 LastLast
Results 1 to 20 of 25
  1. #1
    sus
    sus is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default how to write a program for " world cup " in java

    hi guys ,,,

    im new in this forum ,,, i came here cause i needed help with something

    i was trying to improve my java ,, so i decided to write a program for the world cup " calculates the points and goals .... etc"

    but i had a problem with ranking the teams ,, i used linked lists to list the teams ,,, so this is the method i wrote for sorting teams ,, plz if you could help ill be thankful

    public void sort(){
    Team T1=new Team();
    Team T2=new Team();
    Team T3=new Team();
    Team T4=new Team();
    int max1=0;
    int max2=0;
    int max3=0;
    int max4=0;
    points();// calculates the points depending on how many time the team won or drew
    Node current=first;
    while(current!=null){
    int P=current.data.P;// data.P means the teams points ofcourse data is of type team
    if(P>=max1){
    current.data.rank=1;
    T1=current.data;
    max1=P;
    }
    if(P>=max2&&P<max1){
    current.data.rank=2;
    T2=current.data;
    max2=P;
    }
    if(P>=max3&&P<max2){
    current.data.rank=3;
    T3=current.data;
    max3=P;
    }
    if(P>=max4&&P<max3){
    current.data.rank=4;
    T4=current.data;
    max4=P;
    }
    if(T1.P>current.data.P){
    T4=T3;
    T3=T2;
    T2=T1;
    T1=current.data;
    max4=max3;max3=max2;max2=max1;max1=current.data.P;
    }
    if(T2.P>current.data.P&&T2.P<max1){
    T4=T3;
    T3=T2;
    T2=current.data;
    max4=max3;max3=max2;max2=current.data.P;
    }
    if(T3.P>current.data.P&&T2.P<max2){
    T4=T3;
    T3=current.data;
    max4=max3;max3=current.data.P;
    }
    if(T4.P>current.data.P&&T4.P<max3){
    T4=current.data;
    max4=current.data.P;
    }
    current=current.next;
    }// end while
    this.Empty();// this method empties the linked list
    InsertAtFront(T4);
    InsertAtFront(T3);
    InsertAtFront(T2);
    InsertAtFront(T1);
    }// end method

    thanks in advance

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,790
    Rep Power
    25

    Default

    Can you describe the problem you are having?

  3. #3
    sus
    sus is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default

    well basically i couldnt rank the teams like " first -second -third -fourth" i have to do that depending on the points each team has ,, i tried to do that and empty the list and then insert the teams again ranked and in order

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,790
    Rep Power
    25

    Default

    I don't see any lists in your code. If your objects were in a list then there are sort methods that would do the sorting for you.

  5. #5
    sus
    sus is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default

    i didnt put the whole code here ,, i just put the sorting method

    how can i use the methods youre talking about ?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,790
    Rep Power
    25

    Default

    There are sort() methods for several classes. Go to the API doc for Java, at the top of the page is an "Index" link, click it, then click on the "S" link, then search for "sort(".
    You'll find several classes that have that method.
    Then start reading the doc for those classes.

  7. #7
    sus
    sus is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default

    where is that ?

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,790
    Rep Power
    25

    Default

    where is that ?
    I downloaded my version from the Sun site.
    If you don't know about the Java API doc ???
    What can I say. You MUST know how to use the API doc to be able to do any java programming.

  9. #9
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Quote Originally Posted by sus View Post
    where is that ?
    Java Platform SE 6
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  10. #10
    sus
    sus is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default

    but do i still have to implement it ?
    i read it and it doesnt give me any implementation

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,790
    Rep Power
    25

    Default

    do i still have to implement it
    Do you mean: Do I have to write the code?
    Yes.

  12. #12
    sus
    sus is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default

    yeah ,, thats what i mean

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,790
    Rep Power
    25

    Default

    OK, We'll leave you to it.

  14. #14
    sus
    sus is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default

    so you cant help me ?

  15. #15
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Of course we could help you, but you didn't ask anything specific. Try it yourself, post your best attempt and come back with specific questions.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  16. #16
    sus
    sus is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default

    i did try ,, and i posted my best attempt above ,, and the one question im asking is " how can i sort the teams depending on the points they have "

  17. #17
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    And you got the advice to have have a look at the various sort(......) methods that are available in the API. What have you found out about them? Where are you stuck?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  18. #18
    sus
    sus is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

    Default

    they are not built-in methods ,, so i have to write their code ,, which is my problem in the first place

  19. #19
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Ahem, they are in the API docs, so how do they get there if you have to write them? Norm said that you will need to write code to use them.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  20. #20
    sus
    sus is offline Member
    Join Date
    Jun 2010
    Posts
    12
    Rep Power
    0

Page 1 of 2 12 LastLast

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 04:03 AM
  2. String greeting = "Hello, world!";
    By Gregorius in forum Introductions
    Replies: 2
    Last Post: 01-24-2009, 02:12 AM
  3. Replies: 1
    Last Post: 10-20-2008, 08:35 AM
  4. Help with "Hello World" Program
    By Phantom in forum New To Java
    Replies: 5
    Last Post: 09-05-2008, 10:34 AM
  5. "Jumble" or "Scramble" Program
    By Shadow22202 in forum Java Applets
    Replies: 8
    Last Post: 04-30-2008, 04:42 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
  •