Results 1 to 20 of 25
- 06-21-2010, 03:00 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
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
- 06-21-2010, 03:12 PM #2
Can you describe the problem you are having?
- 06-21-2010, 03:16 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
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
- 06-21-2010, 03:19 PM #4
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.
- 06-21-2010, 03:21 PM #5
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
i didnt put the whole code here ,, i just put the sorting method
how can i use the methods youre talking about ?
- 06-21-2010, 03:26 PM #6
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.
- 06-21-2010, 03:30 PM #7
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
where is that ?
- 06-21-2010, 03:40 PM #8
I downloaded my version from the Sun site.where is that ?
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.
- 06-21-2010, 03:43 PM #9
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 06-21-2010, 03:53 PM #10
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
but do i still have to implement it ?
i read it and it doesnt give me any implementation
- 06-21-2010, 03:56 PM #11
Do you mean: Do I have to write the code?do i still have to implement it
Yes.
- 06-21-2010, 03:57 PM #12
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
yeah ,, thats what i mean
- 06-21-2010, 04:08 PM #13
OK, We'll leave you to it.
- 06-21-2010, 04:11 PM #14
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
so you cant help me ?
- 06-21-2010, 04:14 PM #15
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
- 06-21-2010, 04:16 PM #16
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
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 "
- 06-21-2010, 04:17 PM #17
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
- 06-21-2010, 04:19 PM #18
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
they are not built-in methods ,, so i have to write their code ,, which is my problem in the first place
- 06-21-2010, 04:21 PM #19
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
- 06-21-2010, 04:22 PM #20
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 03:03 AM -
String greeting = "Hello, world!";
By Gregorius in forum IntroductionsReplies: 2Last Post: 01-24-2009, 01:12 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM -
Help with "Hello World" Program
By Phantom in forum New To JavaReplies: 5Last Post: 09-05-2008, 09:34 AM -
"Jumble" or "Scramble" Program
By Shadow22202 in forum Java AppletsReplies: 8Last Post: 04-30-2008, 03:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks