how to get out of this mess
Hello, I tried another way to solve this but the code is a mess now. I can update a record but the record is not updated. And I have to do a lot of the same steps for every team. Anyone who can help me to get out of this mess. Code so far:Â https://github.com/RoelofWobben/tournament Roelof
hello, I think I have to reconsider my classes and reponsibilities Right now Im thinking of this Team : responsinble for team properties Ranking : reponsibilities for checking if a team is in the ranking and updating the team statics Tournament : parsing the ganes and call the right functions on Ranking Can this work or am In making to much classes Roelof Op 24-3-2019 om 19:02 schreef Roelof Wobben:
Hello,
I tried another way to solve this but the code is a mess now.
I can update a record but the record is not updated. And I have to do a lot of the same steps for every team.
Anyone who can help me to get out of this mess.
Code so far:Â https://github.com/RoelofWobben/tournament
Roelof
This is a simple programming-contest sort of exercise. You "need" only two classes. + a Team - knows its name (a String of at most 30 characters) * This should be passed when the Team is created; the rest of the program should NOT call (Team new) and should NEVER see an un#initialize-d Team instance. - knows the number of matches it has won, drawn, and lost (non-negative Integers, initially zero). - can report what it knows - can report the total match count and point score - can be told that it has won, drawn, or lost another match. + a Tournament - has a collection of Teams that it knows by name (a Dictionary) - and an sequence, initially undefined. - can read a set of match triples from a stream, forwarding the information about wins, draws, and losses to Team instances, which are created when a new name is found, - can convert the values of the teams collection to a sorted collection that is sorted by a somewhat vague order, I chose - descending on point score, then - descending on wins, then - ascending on losses, then - ascending on name. - can write the sorted teams to a stream in tabular form. ! Has a class method that does (self new) read: <<source>>; sort; write: <<destination>> Frankly, formatting the output was the hardest part. On Mon, 25 Mar 2019 at 10:00, Roelof Wobben <r.wobben@home.nl> wrote:
hello,
I think I have to reconsider my classes and reponsibilities
Right now Im thinking of this
Team : responsinble for team properties Ranking : reponsibilities for checking if a team is in the ranking and updating the team statics Tournament : parsing the ganes and call the right functions on Ranking
Can this work or am In making to much classes
Roelof
Op 24-3-2019 om 19:02 schreef Roelof Wobben:
Hello,
I tried another way to solve this but the code is a mess now.
I can update a record but the record is not updated. And I have to do a lot of the same steps for every team.
Anyone who can help me to get out of this mess.
Code so far: https://github.com/RoelofWobben/tournament
Roelof
In OOP, you should not be thinking in terms of "updating a record". You should *ask* an object to update *itself*. [aStream atEnd] whileFalse: [ |fields team1 team2 outcome| fields := aStream nextLine subStrings: ';'. team1 := self teamNamed: (fields at: 1). team2 := self teamNamed: (fields at: 2). outcome := fields at: 3. outcome = 'win' ifTrue: [team1 won. team2 lost]. outcome = 'draw' ifTrue: [team1 tied. team2 tied]. outcome = 'loss' ifTrue: [team1 lost. team2 won ]]. (Extracted from a working solution.) On Mon, 25 Mar 2019 at 19:29, Roelof Wobben <r.wobben@home.nl> wrote:
Thanks all
@Richard
I did tried that way in the solution I put on the net. But I get stuck at the point that if I update a record in the Team Class the collection at the Tournament class was not updated.
But right now , I try a new way to make it work that a new team is made and returned or a team is returned if that team is known.
Roelof
Op 25-3-2019 om 06:18 schreef Richard O'Keefe:
This is a simple programming-contest sort of exercise. You "need" only two classes. + a Team - knows its name (a String of at most 30 characters) * This should be passed when the Team is created; the rest of the program should NOT call (Team new) and should NEVER see an un#initialize-d Team instance. - knows the number of matches it has won, drawn, and lost (non-negative Integers, initially zero). - can report what it knows - can report the total match count and point score - can be told that it has won, drawn, or lost another match.
+ a Tournament - has a collection of Teams that it knows by name (a Dictionary) - and an sequence, initially undefined. - can read a set of match triples from a stream, forwarding the information about wins, draws, and losses to Team instances, which are created when a new name is found, - can convert the values of the teams collection to a sorted collection that is sorted by a somewhat vague order, I chose - descending on point score, then - descending on wins, then - ascending on losses, then - ascending on name. - can write the sorted teams to a stream in tabular form. ! Has a class method that does (self new) read: <<source>>; sort; write: <<destination>>
Frankly, formatting the output was the hardest part.
On Mon, 25 Mar 2019 at 10:00, Roelof Wobben <r.wobben@home.nl> wrote:
hello,
I think I have to reconsider my classes and reponsibilities
Right now Im thinking of this
Team : responsinble for team properties Ranking : reponsibilities for checking if a team is in the ranking and updating the team statics Tournament : parsing the ganes and call the right functions on Ranking
Can this work or am In making to much classes
Roelof
Op 24-3-2019 om 19:02 schreef Roelof Wobben:
Hello,
I tried another way to solve this but the code is a mess now.
I can update a record but the record is not updated. And I have to do a lot of the same steps for every team.
Anyone who can help me to get out of this mess.
Code so far: https://github.com/RoelofWobben/tournament
Roelof
Hi Roelof, I probably missed your prior posts but I do have a few questions and/or comments for you before I can be of any help! This code is for tournaments of what sport exactly? Hockey teams? Baseball teams? Or tournaments between players (such as in chess where the concept of Team exists only every 4 years for the chess Olympiads). Do you plan on handling different sports? Different tournament formats (round robin, ladder, etc). The whole thing seems to be centered around games/match results but you don't have such a class in your example. Besides, how do you handle different results for one team for the same tournament a few years apart (say, the 2017 Formula 1 season vs the 2018 Formula 1 season) ? Shouldn't tournaments also have a name and a year (or a Season object) like they have in tennis, golf, chess, hockey, baseball, etc? So my first impression is that you need the following classes : Team, GameResult, Tournament and something like TournamendDirector to create tournaments and create matches (or read/write them). In other words, we need more info on what you are trying to do! On 2019-03-24 14:02, Roelof Wobben wrote:
Hello,
I tried another way to solve this but the code is a mess now.
I can update a record but the record is not updated. And I have to do a lot of the same steps for every team.
Anyone who can help me to get out of this mess.
Code so far:Â https://github.com/RoelofWobben/tournament
Roelof
-- ----------------- Benoît St-Jean Yahoo! Messenger: bstjean Twitter: @BenLeChialeux Pinterest: benoitstjean Instagram: Chef_Benito IRC: lamneth GitHub: bstjean Blogue: endormitoire.wordpress.com "A standpoint is an intellectual horizon of radius zero". (A. Einstein)
participants (3)
-
Benoit St-Jean -
Richard O'Keefe -
Roelof Wobben