Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 04-19-2006, 12:06 AM   #1
Daemon Poster
 
The_Other_One's Avatar
 
Join Date: Sep 2004
Posts: 1,321
Send a message via AIM to The_Other_One
Unhappy Some JAVA help, please?

So here's a program I'm working on for class. It reads Teams.txt(just a list of a team name, a space, then a team's wins) It's then suppose to sort by the number of wins. I got it to read the teams and scores just fine and stick them each in arrays. The problem right now is that every time I do this test, just trying to see if it'll sort at all, I get errors. Not compiler errors, just errors when I run it...

I know it's not perfect, again, this is just a test. Don't ask how I plan to sort both arrays accordingly...I'm not to that point yet

------

import java.io.*;
import java.util.StringTokenizer;
public class Tournament

{
public static void main (String[] args) throws IOException
{
String[] scoresA = new String[64];
String[] teamsA = new String[64];
int x = 0;
String line, name, file = "Teams.txt";
FileReader fr = new FileReader (file);
BufferedReader inFile = new BufferedReader (fr);
line = inFile.readLine();

while (line != null)
{
StringTokenizer tokens = new StringTokenizer(line);
line = inFile.readLine();
teamsA[x] = tokens.nextToken();
scoresA[x] = tokens.nextToken();
x++;
}
inFile.close();
System.out.println(scoresA[1]);
java.util.Arrays.sort(teamsA);
System.out.println(scoresA[1]);
}
}
__________________

__________________
Desktop: Athlon 64 3700, 1024M RAM, GF 6200 TC 256M, 2x 80G, 2x DVD-RW
Laptop: Sempron 2800, 512M RAM, Unichrome, 60G, DVD-RW
Macintosh:G4 1.33GHz, 512M RAM, Radeon 9200 32M, 40G, DVD/CDRW
They get me from 0 to 1...
The_Other_One is offline   Reply With Quote
Old 04-19-2006, 10:52 AM   #2
Daemon Poster
 
uid=[0]'s Avatar
 
Join Date: Apr 2006
Posts: 906
Send a message via Yahoo to uid=[0]
Default Re: Some JAVA help, please?

What is the error that you are getting?
__________________

__________________
"Security is nothing more than a thought that makes you sleep well at night." - Me
MCSE/MCSA
Security+/Network+
Wireless Network Security Spec.
uid=[0] is offline   Reply With Quote
Old 04-19-2006, 01:12 PM   #3
Daemon Poster
 
The_Other_One's Avatar
 
Join Date: Sep 2004
Posts: 1,321
Send a message via AIM to The_Other_One
Default Re: Some JAVA help, please?

I think I got it... As you can see, I just set the arrays to 64, but some of the lists only have 8 or so teams/scores. I think I have to count the lines(or perhaps tokens and divide by 2) and just set the arrays accordingly...
__________________
Desktop: Athlon 64 3700, 1024M RAM, GF 6200 TC 256M, 2x 80G, 2x DVD-RW
Laptop: Sempron 2800, 512M RAM, Unichrome, 60G, DVD-RW
Macintosh:G4 1.33GHz, 512M RAM, Radeon 9200 32M, 40G, DVD/CDRW
They get me from 0 to 1...
The_Other_One is offline   Reply With Quote
Old 04-19-2006, 01:52 PM   #4
Daemon Poster
 
uid=[0]'s Avatar
 
Join Date: Apr 2006
Posts: 906
Send a message via Yahoo to uid=[0]
Default Re: Some JAVA help, please?

Quote:
Originally Posted by The_Other_One
I think I got it... As you can see, I just set the arrays to 64, but some of the lists only have 8 or so teams/scores. I think I have to count the lines(or perhaps tokens and divide by 2) and just set the arrays accordingly...
Trial and error, best way to learn! Glad to hear you got it. Nice!
__________________
"Security is nothing more than a thought that makes you sleep well at night." - Me
MCSE/MCSA
Security+/Network+
Wireless Network Security Spec.
uid=[0] is offline   Reply With Quote
Old 04-19-2006, 08:30 PM   #5
Daemon Poster
 
The_Other_One's Avatar
 
Join Date: Sep 2004
Posts: 1,321
Send a message via AIM to The_Other_One
Default Re: Some JAVA help, please?

OK, I really, really, REALLY need some help! I can't figure out how to get this damn thing to work.

A) How do I count the number of tokens IF I stick with an array?
B) How would I sort, assuming I stick with two different arrays?(both teams and score must change accordingly)
__________________
Desktop: Athlon 64 3700, 1024M RAM, GF 6200 TC 256M, 2x 80G, 2x DVD-RW
Laptop: Sempron 2800, 512M RAM, Unichrome, 60G, DVD-RW
Macintosh:G4 1.33GHz, 512M RAM, Radeon 9200 32M, 40G, DVD/CDRW
They get me from 0 to 1...
The_Other_One is offline   Reply With Quote
Old 04-20-2006, 06:11 AM   #6
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,003
Default Re: Some JAVA help, please?

for sorting I suggest that you google "bubble sort".
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 04-20-2006, 11:27 AM   #7
Daemon Poster
 
The_Other_One's Avatar
 
Join Date: Sep 2004
Posts: 1,321
Send a message via AIM to The_Other_One
Default Re: Some JAVA help, please?

I'll check that out, but I still got to get the arrays correctly...
__________________
Desktop: Athlon 64 3700, 1024M RAM, GF 6200 TC 256M, 2x 80G, 2x DVD-RW
Laptop: Sempron 2800, 512M RAM, Unichrome, 60G, DVD-RW
Macintosh:G4 1.33GHz, 512M RAM, Radeon 9200 32M, 40G, DVD/CDRW
They get me from 0 to 1...
The_Other_One is offline   Reply With Quote
Old 04-20-2006, 12:19 PM   #8
Daemon Poster
 
The_Other_One's Avatar
 
Join Date: Sep 2004
Posts: 1,321
Send a message via AIM to The_Other_One
Default Re: Some JAVA help, please?

Would there be a way that I could say take an array of strings with something like "UNCC 17" in each string, and sort by the number at the end? I know I can just read the array and display the number using the string tokenizer, but I don't know if it's possible to use this while sorting...
__________________
Desktop: Athlon 64 3700, 1024M RAM, GF 6200 TC 256M, 2x 80G, 2x DVD-RW
Laptop: Sempron 2800, 512M RAM, Unichrome, 60G, DVD-RW
Macintosh:G4 1.33GHz, 512M RAM, Radeon 9200 32M, 40G, DVD/CDRW
They get me from 0 to 1...
The_Other_One is offline   Reply With Quote
Old 04-20-2006, 04:01 PM   #9
Baseband Member
 
Bozorg's Avatar
 
Join Date: Mar 2006
Posts: 34
Send a message via AIM to Bozorg Send a message via MSN to Bozorg
Default Re: Some JAVA help, please?

Have you thought about making a "team" class and have it have 2 variables. one with the team name and another with the score. Then in your tournament class make an array of the "team" class and then you would be able to sort both the name and the scores while just sorting the scores.

Thats how I would go at the problem.
Bozorg is offline   Reply With Quote
Old 04-20-2006, 04:20 PM   #10
Daemon Poster
 
The_Other_One's Avatar
 
Join Date: Sep 2004
Posts: 1,321
Send a message via AIM to The_Other_One
Default Re: Some JAVA help, please?

Someone suggested that but I have no clue how I would even start doing that...

Now, I once had two arrays, one with the name one with the score. The problem there is how would you go about sorting them? YOu can sort the scroes, but the teams wouldn't sort with them...
__________________

__________________
Desktop: Athlon 64 3700, 1024M RAM, GF 6200 TC 256M, 2x 80G, 2x DVD-RW
Laptop: Sempron 2800, 512M RAM, Unichrome, 60G, DVD-RW
Macintosh:G4 1.33GHz, 512M RAM, Radeon 9200 32M, 40G, DVD/CDRW
They get me from 0 to 1...
The_Other_One is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 08:42 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0