Steve Haggan wrote:Hi, I hope someone can give me some valuable pointers.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Steve Haggan wrote:I have been provided with two text files, one is a league table of football teams and their current points which I have stored into two separate arrays - teams and points
The second text file is a list of teams and their last results, however the results are in text form thus I have had to amend to include numeric values i.e 3, 1 or 0.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Barcelona 34
Real Madrid 32
Villareal 27
Espanyol 25
Red Smith wrote:although you would need to use the other StringTokenizer constructor:
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Red Smith wrote:although you would need to use the other StringTokenizer constructor:
@Steve - That reminds me: Have you been specifically asked to use StringTokenizer? Because it's a legacy class, and its use is generally discouraged. The Scanner class (java.util.Scanner) can do pretty much everything that ST does, and you can use it on Strings or Streams.
Winston
Steve Haggan wrote:Thanks Winston, I'll make sure the next time all code is input correctly
there are twenty teams and their points tally
The second table is their results last match:
Villareal drew
.....
So for each of the teams there is either won, lost or drew
I then need to convert won to 3 point, lost to 0 and drew to 1 point.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Steve Haggan wrote:Yes we were asked to use String Tokenizer, I know some of my more knowledgeable class mates queried this as it is an older class.
StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Steve Haggan wrote:Thanks Winston, I'll make sure the next time all code is input correctly
OK. Cheers.
there are twenty teams and their points tally
Tally with what? Seems to me that without knowing how many matches they've played, you can't tell whether they tally or not - or have you been told to assume that they tally?
The second table is their results last match:
Villareal drew
.....
So for each of the teams there is either won, lost or drew
I then need to convert won to 3 point, lost to 0 and drew to 1 point.
OK, so that sounds like something you could turn into a function (except in Java they're called methods), eg:then you could update your table with the result of this method, viz:
The above is just a very small example of what you should be doing as much as possible - break the problem down into small, manageable steps.
And I hate to say it, but in order to do that properly, you need to stop coding, get out a pencil and paper, and write down what those steps are, in English (or your native language).
You will never code your way out of a jam.
Winston
Steve Haggan wrote:It makes much more sense in my head, and apologies again if its not clear what I need.
I'll get my pen and paper out.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Steve Haggan wrote:...therefore I need to scan the first array, find Real Madrid and then find the corresponding element for Real Madrdid in the points array.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Steve Haggan wrote:...therefore I need to scan the first array, find Real Madrid and then find the corresponding element for Real Madrdid in the points array.
Which I presume will have the same index.
Again, this sounds to me like a step (or a "task"), so why not write a method that takes a team name and scans your teams array looking for it. If it finds it, it returns the index where it was found; otherwise -1 (which can't possibly be a valid index).
Do you see how that might help?
Winston
Steve Haggan wrote:I am using the tokenizer, so Real Madrid has two tokens, Barcelona will be one token, how do I tell the method what to scan for?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Steve Haggan wrote:
Winston Gutkowski wrote:
Steve Haggan wrote:...therefore I need to scan the first array, find Real Madrid and then find the corresponding element for Real Madrdid in the points array.
Which I presume will have the same index.
Again, this sounds to me like a step (or a "task"), so why not write a method that takes a team name and scans your teams array looking for it. If it finds it, it returns the index where it was found; otherwise -1 (which can't possibly be a valid index).
Do you see how that might help?
Winston
Thats what I was thinking but where I think I have a knowledge gap is telling java what to search for.
I am using the tokenizer, so Real Madrid has two tokens, Barcelona will be one token, how do I tell the method what to scan for?
i.e. first scan searches for Real Madrid and returns its element in the array, then scans for Barcelona and scans for that element in the array.
Thanks for your help and patience by the way.